このコードは単純なアプリケーションで正常に機能しているため、ドライバーは正常です。それで、接続オブジェクトがドライバーで初期化できないのはなぜですか。
import java.sql.Connection;
インポートjava.sql.DriverManager;
インポートjava.sql.SQLException;
インポートjava.sql.Statement;
インポートcom.opensymphony.xwork2.ActionSupport;
public class Insert extends ActionSupport {
public String execute() throws Exception, SQLException {
String sql = "";
String url = "jdbc:mysql://localhost:3306/test";
//String dbName = "test";
String driverName = "org.gjt.mm.mysql.Driver";
String userName = "root";
String password = "root";
Connection con=null;
Statement stmt=null;
try {
Class.forName(driverName).newInstance();
con = DriverManager.getConnection(url, userName, password);
stmt = con.createStatement();
} catch (Exception e) {
System.out.println(e.getMessage());
}
}