喜悦国际村 
» 游客:  注册 | 登录 | 搜索 | 统计 | 喜悦证交所 | 帮助

RSS 订阅当前论坛  

[北京]代朋友公司招聘PHP高级程序员多名

上一主题 下一主题
     
标题: 莫名其妙的错误(关于jdbc)  
 
yingxin (yingxin)
新手上路
Rank: 1
初级会员



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 = "jdbcdbc: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)
2006-2-24 04:23 PM#1
查看资料  访问主页  发短消息  QQ  顶部
     


  可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题 | 开通个人空间  


 




Powered by Discuz! 6.1.0  © 2001-2010 Comsenz Inc.
Processed in 0.022389 second(s), 6 queries

(冀ICP备05009913号) 管理员:sadly 邮箱/MSN: sadly@phpx.com QQ:824008(长隐) 清除 Cookies - - Archiver - WAP