我已經做了一個數據庫連接來從代碼中獲取數據,現在我需要保持這個db實例全局,並且需要在項目的其他部分使用。dbn conn global
請引導我一樣。
我有下面的代碼
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();
}
什麼不起作用? – spydon
事情工作正常,但我需要幫助,使全球數據庫連接。 – Benjamin