Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java EE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 使用连接池的问题!
feiling





发贴: 26
积分: 0
于 2006-11-09 13:15 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
test.jsp:
<%@page import="javax.sql.DataSource" %>
<%@page import="javax.naming.InitialContext" %>
<%@page import="java.sql.*" %>
<%
DataSource ds=null;
Connection conn=null;
try{
Context initCtx=new InitialContext();
Context envCtx=(Context)initCtx.lookup("java:comp/env");
ds=(DataSource)envCtx.lookup("jdbc/shop");
if(ds!=null)
{
out.println("已经获得数据源!");
out.println("<br/>");
try{
conn=ds.getConnection();
out.println("连接数据库成功");
}catch(Exception e){out.println("连接失败~"+e);}
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from userInfo");
while(rs.next())
{
out.println("用户名:"+rs.getString(1));
}
}
else
out.println("连接失败!");
}catch(Exception e){out.printlnEnvelope;}
%>
获取数据源是成功的...
server.xml中我是添加了这样的描述:
<Context path="/ds" docBase="ds" debug="0" reloadable="true" crossContext="true">
<Resource name="jdbc/shop" auth="Container" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/shop">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
</parameter>
<parameter>
<name>url</name>


<value>jdbc:microsoft.sqlserver://127.0.0.1:1433;DatabaseName=shop</value>
</parameter>
<parameter>
<name>username</name>
<value>root</value>
</parameter>
<parameter>
<name>password</name>
<value>password</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>20</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>10</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>-1</value>
</parameter>
</ResourceParams>
</Context>
运行时发生下面的错误:
已经获得数据源!
连接失败~org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null' java.lang.NullPointerException
看了很久也不知道哪里错了...请好心人指点一下...



作者 Re:使用连接池的问题! [Re:feiling]
liangx





发贴: 37
积分: 0
于 2007-01-22 17:43 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我也遇到过同样的问题,不过现在解决了。

应该在web应用的配置文件web.xml中要配置<resource-ref>的参数吧。
如果你有配置请贴上来看看



作者 Re:使用连接池的问题! [Re:feiling]
wmkm0113





发贴: 6
积分: 1
于 2007-01-26 14:04 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
感觉像是数据库驱动或者数据库连接URL的问题,还是把配置文件贴上来看看吧。


生来为了追寻不灭的灵魂,呼喊出生命的轨迹与不死的理想。

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923