yingxin
(yingxin)
新手上路

初级会员
UID 68845
精华
0
积分 1
帖子 1
金钱 1 喜悦币
威望 0
人脉 0
阅读权限 10
注册 2006-2-24
状态 离线
|
莫名其妙的错误(关于jdbc)
我写的一个JDBC连接数据库的JSP文件,内容如下:
<%@ page contentType="text/html; charset=GBK" errorPage="lj2.jsp" %>
<%@ page import="java.sql.*"%>
<%@ page import="java.io.*"%>
<html>
<head>
<title>
lj1
</title>
</head>
<body bgcolor="#ffffff">
<h1>
J
</h1>
<%
String url = "jdbc dbc:ks"; //ks为odbc数据源的名称
String sql = null;
Connection conn = null;
Statement stmt = null;
try {
//第一步:加载驱动器
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch(ClassNotFoundException e) {
out.print("加载驱动器出错!");
}
try {
//第二步:调用DriverManager.getConnection静态方法得到数据库连接
conn = DriverManager.getConnection(url,"sa","");
//创建Statement语句
stmt = conn.createStatement();
sql = "INSERT INTO 用户注册 VALUES('12', 'zhang')";
//使用Statement语句对象执行SQL语句
stmt.executeUpdate(sql);
out.println("我终于连接成功了!");
} catch(SQLException e) {
out.println("sql语句执行出错!!");
} finally {
//关闭语句和数据库连接
try {
stmt.close();
conn.close();
} catch(SQLException e) {
out.println("Close SQLException ");
}
}
%>
</body>
</html>
在JBiulder里调试是正常的,可用tomcat在IE中运行却有错误,是何缘故?错误信息如下:
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:370)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.lang.NullPointerException
org.apache.jsp.lj1_jsp._jspService(org.apache.jsp.lj1_jsp:87)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
|
|