| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 572 人关注过本帖
标题:老问题jdbc连接oracle
只看楼主 加入收藏
要学
Rank: 1
来 自:内蒙
等 级:新手上路
帖 子:23
专家分:0
注 册:2009-9-11
结帖率:44.44%
收藏
已结贴  问题点数:5 回复次数:2 
老问题jdbc连接oracle
代码:
   <%@ page language="java" contentType="text/html; charset=GB2312" pageEncoding="GB2312"%>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
<title>创建数据库</title>
</head>
<body ><font size=2>
    <%   
        //连接需要的对象
        Connection conn = null;
        Statement stmt = null;
        String sql = null;
        ResultSet rs = null;
        int ret;
    try{
   
        Class.forName("oracle.jdbc.Driver.OracleDriver");                    //载入JDBC驱动程序
        String strCon = "jdbc:oracle:thin:@localhost:1521:JamSamples";            //连接字
        conn = DriverManager.getConnection(strCon,"","");    //连接数据库
        stmt = conn.createStatement();                            //初始化查询
        sql = "create database JspSamples";                        //创建数据库
        ret  = stmt.executeUpdate(sql);                        //执行创建数据库
        sql = "use JspSamples";                                //选择数据库
        ret  = stmt.executeUpdate(sql);                        //执行选择数据库
        sql = " CREATE TABLE customers(" +                    //创建表
                " Id int(6) unsigned NOT NULL auto_increment," +
                " Name varchar(20) default NULL," +
                " addTime timestamp NULL default NULL," +
                "  Tel varchar(15) default NULL," +
                "  Email varchar(20) default NULL," +
                "  PRIMARY KEY  (Id)" +
                " )";
        ret  = stmt.executeUpdate(sql);                        //执行创建表
        
    }
    catch(ClassNotFoundException e){                            //意外处理,驱动程序无法找到
        e.printStackTrace();
        out.println("<h1>无法找到数据库驱动</h1>");
    }
    catch(SQLException e1){                                    //意外处理,数据库操作失败
        e1.printStackTrace();
        out.println("<h1>数据库操作失败</h1>");
    }
   
    out.println("<h1>新建数据库JspSamples成功</h1>");
        out.println("<h1>新建数据库JspSamples成功</h1>");
        DatabaseMetaData meta = conn.getMetaData();                //获取数据库信息
        out.println("<br>");
        out.println("连接字:" + meta.getURL());                        //获取连接字
        out.println("<br>");
        out.println("数据库产品:" + meta.getDatabaseProductName());    //获取数据库产品名
        out.println("<br>");
        out.println("数据库版本:" + meta.getDatabaseProductVersion() );    //获取数据库产品版本
        out.println("<br>");
        out.println("驱动程序:" + meta.getDriverName() );                //获取数据库驱动名
        out.println("<br>");
        out.println("驱动程序版本:"  + meta.getDriverVersion() );        //获取数据库驱动版本
        stmt.close();                                        //关闭查询
        conn.close();                                        //关闭连接
    %>
</font>
</body>
</html>
错误:
   Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:460)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)


root cause

java.lang.NullPointerException
    org.apache.jsp.Ex5_005f1_jsp._jspService(Ex5_005f1_jsp.java:94)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)


note The full stack trace of the root cause is available in the Apache Tomcat/5.5.27 logs.

我的问题好久老解决不了,好困惑啊!帮帮我啊!小弟谢了
搜索更多相关主题的帖子: jdbc oracle 
2010-04-18 10:39
linjx0123
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:279
专家分:1362
注 册:2006-4-7
收藏
得分:1 
你页面本身没有错误,可能的错误有几个:
1 没有把oracle的driver放进web-inf/lib下
2 没有创建数据库JamSamples,导致连接不了
String strCon = "jdbc:oracle:thin:@localhost:1521:JamSamples";
这里指定了数据库名称
2010-04-19 09:25
画圈成句点
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:62
专家分:143
注 册:2010-3-28
收藏
得分:1 
localhost  改成你设置的Ip试一下
2010-04-19 10:31
快速回复:老问题jdbc连接oracle
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019452 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved