コード内のデータからフェッチするためのデータベース接続を作成しましたが、このデータベース インスタンスをグローバルに維持し、プロジェクトの他の部分で使用する必要があります。
同じように私を案内してください。
私は以下のコードを持っています
try
{
// load the DB2 Driver
Class.forName("com.ibm.db2.jcc.DB2Driver");
// establish a connection to DB2
Connection db2Conn = DriverManager.getConnection
(dbUrl,"wcsadm",dbPass);
// use a statement to gather data from the database
Statement st = db2Conn.createStatement();
String myQuery=null;
String insQuery=null;
myQuery = "my query"
// execute the query
ResultSet resultSet = st.executeQuery(myQuery);
// cycle through the resulSet and display what was grabbed
while (resultSet.next())
{
//do something
}
resultSet.close();
st.close();
db2Conn.close();
}