关于JSP中的空指针问题
用javabean连的数据库,这是javabean中的部分代码publicclassconnection{privateStatementstmt=null;Result...
用javabean连的数据库,这是javabean中的部分代码
public class connection
{
private Statement stmt = null;
ResultSet rs = null;
private Connection conn = null ;
private String dsn;
public connection() { }
public Connection getConn(String uid, String pwd) throws Exception
{
try{
dsn = "jdbc:sqlserver://localhost:1433;DatabaseName = MyHospital" ;
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
conn = DriverManager.getConnection(dsn, uid, pwd);
}
catch (Exception ex)
{
System.err.println("aq.executeQueryConn: " + ex.getMessage());
}
return conn;
}
在jsp中的部分代码:
<% sql = "select Item,DoctorName,Dgender,Dworkdate,Dintroduction, Dphone from Doctors where ItemID='"+ItemID+"'";
Connection conn = connection.getConn("sa","sql2008");
Statement stmt = null ; stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
%>
之前一句一句测试了一下,到connection那句还是好的,至少网页还能处得来,到Statement 那句就报错说是空指针
报错信息:
java.lang.NullPointerException
org.apache.jsp.DoctorSearchResult_jsp._jspService(DoctorSearchResult_jsp.java:106)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
能帮我看一下到底哪里出现空指针了?该怎么改? 展开
public class connection
{
private Statement stmt = null;
ResultSet rs = null;
private Connection conn = null ;
private String dsn;
public connection() { }
public Connection getConn(String uid, String pwd) throws Exception
{
try{
dsn = "jdbc:sqlserver://localhost:1433;DatabaseName = MyHospital" ;
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
conn = DriverManager.getConnection(dsn, uid, pwd);
}
catch (Exception ex)
{
System.err.println("aq.executeQueryConn: " + ex.getMessage());
}
return conn;
}
在jsp中的部分代码:
<% sql = "select Item,DoctorName,Dgender,Dworkdate,Dintroduction, Dphone from Doctors where ItemID='"+ItemID+"'";
Connection conn = connection.getConn("sa","sql2008");
Statement stmt = null ; stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
%>
之前一句一句测试了一下,到connection那句还是好的,至少网页还能处得来,到Statement 那句就报错说是空指针
报错信息:
java.lang.NullPointerException
org.apache.jsp.DoctorSearchResult_jsp._jspService(DoctorSearchResult_jsp.java:106)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
能帮我看一下到底哪里出现空指针了?该怎么改? 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询