이 코드는 간단한 애플리케이션에서 잘 작동하므로 드라이버는 문제가 없습니다. 그래서 연결 개체를 드라이버로 초기화 할 수없는 이유는 무엇입니까?연결 객체가 null이되기 때문에 MySQL 데이터베이스에 레코드를 삽입하지 않는 Struts2 예제
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import com.opensymphony.xwork2.ActionSupport;
공용 클래스 삽입 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());
}
을}
오류 메시지 –