jsp的java.lang.NullPointerException问题!
程序为:<%@pagecontentType="text/html;charset=gb2312"%><%@pageimport="java.sql.*"%><%!Str...
程序为:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<%!
String driver="sun.jdbc.odbc.JdbcOdbcDriver";
String url="jdbc:odbc:mldn";
String user="sa";
String password="";
Connection conn=null;
Statement pstmt=null;
ResultSet rs=null;
String sql=null;
%>
<%
try
{
Class.forName(driver);
}catch(Exception e){e.printStackTrace();}
try
{
conn=DriverManager.getConnection(url);
}catch(Exception e){e.printStackTrace();}
try
{
pstmt=conn.createStatement();
conn.setAutoCommit(false);
pstmt.addBatch("use long INSERT INTO person (姓名,id) VALUES ('LXH_A',28)");
pstmt.addBatch("use long INSERT INTO person (姓名,id) VALUES ('LXH_b',22)");
pstmt.addBatch("use long INSERT INTO person (姓名,id) VALUES ('LXH_c',23)");
pstmt.executeBatch();
conn.commit();
}catch(Exception e)
{
try
{
conn.rollback();
}catch(Exception ee){}
out.println("数据库关闭失败!!!") ;
}
try
{
rs.close();
pstmt.close();
conn.close();
}catch(Exception e){e.printStackTrace();}
%>
错误为:
java.lang.NullPointerException
at org.apache.jsp.jdbc2_jsp._jspService(jdbc2_jsp.java:97)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source) 展开
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<%!
String driver="sun.jdbc.odbc.JdbcOdbcDriver";
String url="jdbc:odbc:mldn";
String user="sa";
String password="";
Connection conn=null;
Statement pstmt=null;
ResultSet rs=null;
String sql=null;
%>
<%
try
{
Class.forName(driver);
}catch(Exception e){e.printStackTrace();}
try
{
conn=DriverManager.getConnection(url);
}catch(Exception e){e.printStackTrace();}
try
{
pstmt=conn.createStatement();
conn.setAutoCommit(false);
pstmt.addBatch("use long INSERT INTO person (姓名,id) VALUES ('LXH_A',28)");
pstmt.addBatch("use long INSERT INTO person (姓名,id) VALUES ('LXH_b',22)");
pstmt.addBatch("use long INSERT INTO person (姓名,id) VALUES ('LXH_c',23)");
pstmt.executeBatch();
conn.commit();
}catch(Exception e)
{
try
{
conn.rollback();
}catch(Exception ee){}
out.println("数据库关闭失败!!!") ;
}
try
{
rs.close();
pstmt.close();
conn.close();
}catch(Exception e){e.printStackTrace();}
%>
错误为:
java.lang.NullPointerException
at org.apache.jsp.jdbc2_jsp._jspService(jdbc2_jsp.java:97)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source) 展开
4个回答
展开全部
报错信息中:“at org.apache.jsp.jdbc2_jsp._jspService(jdbc2_jsp.java:97)"提示你jdbc2_jsp.java文件中的第97行代码出现错误,您可以自己检查一下,java.lang.NullPointerException这种错误一般来说都是对象或者变量的值为空导致的。这种问题您可以自己解决的,仔细检查一下吧!!
实在不行,你就用System.out.println输出一下jdbc2_jsp.java文件中第97行所涉及的的对象的内存地址或者变量的值,看一下是否为"null",我估计九成都是null;呵呵!!
实在不行,你就用System.out.println输出一下jdbc2_jsp.java文件中第97行所涉及的的对象的内存地址或者变量的值,看一下是否为"null",我估计九成都是null;呵呵!!
展开全部
可能是你的ODBC设置的问题 你检查下你的odbc设置了没,要是这里没问题的话你根据错误提示看下,先在数据库连接的程序块里加一个System.out.println("数据库连接成功!");要是运行程序后输出了这个代码那就是数据库已经连接上 odbc连接没有问题。在检查下其他地方,类似此方法。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
可能是数据库的连接问题。(建议:虽然jsp也是servlet,但脚本最好不要放在jsp页面中)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询