Struts2 example, not inserting records in mysql database because connection object is getting null
Posted
by Jugal
on Stack Overflow
See other posts from Stack Overflow
or by Jugal
Published on 2009-04-04T11:59:50Z
Indexed on
2010/03/15
6:49 UTC
Read the original article
Hit count: 548
struts2
This Code is working fine with simple application so the drivers are fine. so why the connection object is not able to initialise with drivers.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import 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());
}
}
© Stack Overflow or respective owner