ローカルのMySQLデータベースにいくつかの値を挿入しようとしているStruts 2を使ってWebアプリケーションを開発しています。StrutsでTomcat 7でJDBCを使用すると問題が発生する
データベースに接続してアクセスするためのコードは、コンソールアプリケーションで正常に機能します。
ただし、Strutsで同じコードを実行すると、java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
の例外が発生します。
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/";
String dbName = "testdatabase";
String driver = "com.mysql.jdbc.Driver";
try
{
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName,"root","root");
Statement statement=conn.createStatement();
System.out.println("HelloWorld.execute()");
int i= statement.executeUpdate("INSERT INTO testTable VALUES('15','Lucky')");
System.out.println("res: "+i);
}
catch(Exception e)
{
System.out.println(e);
//setMessage(e.getMessage());
}
ありがとうございます... – Chethu2288