hai,
i am trying this i am getting null pointer exception at Db.insertData();
<jsp:useBean id="Db" scope="session" class="DataBaseConnect">
</jsp:useBean>
<%
String sql=null;
sql="insert into employee(job_desc,emp_name) values ('manager','xxxx')";
Db.openConn();
Db.insertData(sql);
Db.closeStmt();
Db.closeConn();
%>
bean code:
import java.sql.*;
import java.io.*;
public class DataBaseConnect {
Connection con = null;
Statement stmt = null;
ResultSet result = null;
public DataBaseConnect() {}
public void openConn() throws Exception {
try {
Class.forName("com.jnetdirect.jsql.JSQLDriver"
String sHost = "127.0.0.1";
con = DriverManager.getConnection
("jdbc:JSQLConnect://"+sHost+"/database=res&user=sa"
} catch (Exception e) {
e.printStackTrace();
}
}
public void insertData(String query) throws Exception{
stmt=con.createStatement();
int i=stmt.executeUpdate(query);
}
public void closeStmt()
throws Exception {
stmt.close();
stmt = null;
}
public void closeConn()
throws Exception {
con.close();
con = null;
}
}
please help me .
what is the problem
i am trying this i am getting null pointer exception at Db.insertData();
<jsp:useBean id="Db" scope="session" class="DataBaseConnect">
</jsp:useBean>
<%
String sql=null;
sql="insert into employee(job_desc,emp_name) values ('manager','xxxx')";
Db.openConn();
Db.insertData(sql);
Db.closeStmt();
Db.closeConn();
%>
bean code:
import java.sql.*;
import java.io.*;
public class DataBaseConnect {
Connection con = null;
Statement stmt = null;
ResultSet result = null;
public DataBaseConnect() {}
public void openConn() throws Exception {
try {
Class.forName("com.jnetdirect.jsql.JSQLDriver"
String sHost = "127.0.0.1";
con = DriverManager.getConnection
("jdbc:JSQLConnect://"+sHost+"/database=res&user=sa"
} catch (Exception e) {
e.printStackTrace();
}
}
public void insertData(String query) throws Exception{
stmt=con.createStatement();
int i=stmt.executeUpdate(query);
}
public void closeStmt()
throws Exception {
stmt.close();
stmt = null;
}
public void closeConn()
throws Exception {
con.close();
con = null;
}
}
please help me .
what is the problem