JSP中引用一个外部数据库连接池的错误

HF_SKY000 2010-09-20 01:04:35
在工程目录下有一个数据库连接池的类ConnectionPool,文件名为:ConnectionPool.java

在JSP中我想引入数据库连接池。开发环境是:Myeclipse + Tomcat.相关代码为:

<body>
<h2>查询结果:</h2>
<%!String sql="select username,password from sa.user";%>
<%
ConnectionPool pool =new ConnectionPool(
"oracle.jdbc.driver.OracleDriver",
"jdbc:oracle:thin:@100.200.100.1:1521:ORACLEDB",
"sa",
"sa"
);
pool.createPool();
Connection con =pool.getConnection();
PreparedStatement stmt =con.prepareStatement(sql);
ResultSet rs =stmt.executeQuery();
ResultSetMetaData rsData =rs.getMetaData();
out.println("<table border='1'>");
while(rs.next()){
out.println("<tr><th>"+rsData.getColumnLabel(0)+"</th></tr>");
out.println("<tr><th>"+rsData.getColumnLabel(1)+"</th></tr>");
}
out.println("</table>");
con.close();
pool.closeConnectionPool();
%>
</body>

报错信息有:
org.apache.jasper.JasperException: An exception occurred processing JSP page /DisplyDBInformation.jsp at line 23

20: "nmsdb",
21: "nmsdb"
22: );
23: pool.createPool();
24: Connection con =pool.getConnection();
25: PreparedStatement stmt =con.prepareStatement(sql);
26: ResultSet rs =stmt.executeQuery();


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:401)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause

javax.servlet.ServletException: java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
org.apache.jsp.DisplyDBInformation_jsp._jspService(DisplyDBInformation_jsp.java:106)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause

java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1645)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491)
java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Class.java:169)
com.bird.beans.ConnectionPool.createPool(ConnectionPool.java:206)
org.apache.jsp.DisplyDBInformation_jsp._jspService(DisplyDBInformation_jsp.java:84)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

...全文
40 点赞 收藏 6
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
HF_SKY000 2010-09-20
[Quote=引用 5 楼 changjiangzhibin 的回复:]
不加载驱动包是不行的
[/Quote]

我的问题是这样的:

我把驱动包只放到Tomcat的lib下,没有在Myeclipse没有配制build path就可以跑起来?这是何道理?

回复
changjiangzhibin 2010-09-20
不加载驱动包是不行的
回复
HF_SKY000 2010-09-20
果然是高手呀,

我发现把ORACLE的驱动包放到Tomcat的lib目录下,在Myeclipse里也没有添加,直接运行就OK了,

跟Java运用程序不一样呀。

这是何道理呀?
回复
wuxiaoke2009 2010-09-20
没有将该驱动包 添加进来哈
回复
wjf8882300 2010-09-20
要把ConnectionPool.java所在的那个包导进来
在前面加<%import ....%>
回复
dqsweet 2010-09-20
驱动包要复制到 tomcat 的lib 下
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2010-09-20 01:04
社区公告
暂无公告