JSP如何对SQLSERVER表进行操作?

钟伟海 国新健康保障服务有限公司 大数据  2002-03-04 05:07:57
出现如下错误:
是什么原因呢?
Error: 500
Location: /database.jsp
Internal Servlet Error:

javax.servlet.ServletException
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:459)
at _0002fdatabase_0002ejspdatabase_jsp_2._jspService(_0002fdatabase_0002ejspdatabase_jsp_2.java:179)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspCountedServlet.service(JspServlet.java:130)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:282)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:429)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:500)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)
at org.apache.tomcat.core.Handler.service(Handler.java:287)
at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:812)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:758)
at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:213)
at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
at java.lang.Thread.run(Thread.java:539)

Root cause:
java.lang.NullPointerException
at _0002fdatabase_0002ejspdatabase_jsp_2._jspService(_0002fdatabase_0002ejspdatabase_jsp_2.java:94)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspCountedServlet.service(JspServlet.java:130)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:282)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:429)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:500)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)
at org.apache.tomcat.core.Handler.service(Handler.java:287)
at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:812)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:758)
at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:213)
at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
at java.lang.Thread.run(Thread.java:539)

...全文
6 点赞 收藏 6
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
Kin_CIOM 2002-03-06
妳的Con為null,Con.createStatement 會有值嗎,使用null指針一定出錯?
回复
yanchang 2002-03-06
java.sql.Statement Stmt = Con.createStatement ();
错了!
该为
java.sql.Statement Stmt = null;
回复
waterdragonfly 2002-03-06
Connection Con = null;
java.sql.Statement Stmt = Con.createStatement ();
这两句有必要吗?
回复
钟伟海 2002-03-05
我的database.jsp如下:
<%@ page contentType="text/html; charset=gb2312" %>
<%@ page info="database handler"%>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.servlet.*"%>
<%@ page import="javax.servlet.http.*"%>
<%@ page import = "java.net.URL" %>

<html>
<head>
<title>数据库连接实验</title>
</head>
<body>
<%

Connection Con = null;
java.sql.Statement Stmt = Con.createStatement ();
try
{
try /*加载驱动程序*/
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}
catch(java.lang.ClassNotFoundException e)
{
out.print("Connect to Database error: " + e.getMessage());
}
try /*建立连接*/
{
Con=DriverManager.getConnection("jdbc:sqlserver://zwh:1433;user=sa;password=;DatabaseName=test");
}
catch(SQLException e)
{
out.print(e.toString());
}
Stmt = Con.createStatement();
String query="CREATE TABLE GUEST" + "(NUM VARCHAR(32),"+
"USERNAME TEXT,"+
"CONTENT TEXT,"+
"PASSWORD INTEGER,"+
"TOTAL INTEGER,"+
"REALNAME TEXT)";
Stmt.executeUpdate(query); /*更新数据库*/
}
catch (Exception e) {}

out.println("恭喜,表连接创建成功!");
%>
</body>
</html>

是哪里不对吗?
回复
yanchang 2002-03-04
空指针?!
回复
Kin_CIOM 2002-03-04
database.jsp中的代碼是什么啊?
回复
发动态
发帖子
Web 开发
创建于2007-09-28

7.9w+

社区成员

Java Web 开发
申请成为版主
社区公告
暂无公告