Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

database connection bean to jsp

Status
Not open for further replies.

daka94

Programmer
Apr 27, 2001
33
US
hai,
i am trying this i am getting null pointer exception at Db.insertData();
<jsp:useBean id=&quot;Db&quot; scope=&quot;session&quot; class=&quot;DataBaseConnect&quot;>
</jsp:useBean>
<%
String sql=null;
sql=&quot;insert into employee(job_desc,emp_name) values ('manager','xxxx')&quot;;
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(&quot;com.jnetdirect.jsql.JSQLDriver&quot;);
String sHost = &quot;127.0.0.1&quot;;
con = DriverManager.getConnection
(&quot;jdbc:JSQLConnect://&quot;+sHost+&quot;/database=res&user=sa&quot;);
} 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
 
Please post the entire stack trace. My for inclination is to think the Connection is not getting created correctly and it is still null when the call to insertData() is made. Also a quick note, to improve your code, your instance variables should be private. There are also a few other changes I would make but let's get this working first. Wushutwist
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top