eclipse IDE を使用して動的 Web アプリケーションを開発し、Tomcat 7.0 を使用して war ファイルをデプロイしています。でurl、ユーザー名、およびパスワードパラメーターを渡すことにより、メソッドを介してデータベースに接続しようとしていますgetConnection()
。
db2jcc
jar を tomcat lib フォルダーに配置しました。次のようにSQL例外が発生しています
No suitable driver found for jdbc:DB2://localhost:50000/InstanceName
Eclipse サーバーコンソールで。この問題を克服する方法に関する提案。
protected Statement dynamiCreateDBStatement(String url, String DB_Uname,String DBPWD,String DB_Type)
{
try {
System.out.println(url+"uname="+DB_Uname+"pwd="+DBPWD);
if(DB_Type.equals("") || DB_Type.equals("null") == false)
{
if(DB_Type.equalsIgnoreCase("DB2"))
{
Class.forName("com.ibm.db2.jcc.DB2Driver");
}
if(DB_Type.equalsIgnoreCase("oracle"))
{
Class.forName("oracle.jdbc.OracleDriver");
}
}
String type="javax.sql.DataSource";
connection1 = DriverManager.getConnection(url, DB_Uname, DBPWD);
stmt1 = connection1.createStatement();
connection1.close();
System.out.println("close conn to db=="+connection1.isClosed());
return stmt1;
} catch (SQLException e) {
// TODO Auto-generated catch block
System.out.println("sql ="+e.getMessage());
return null;
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
System.out.println("class=="+e.getMessage());
return null;
}
}