Topic: 用连接池连接数据库的问题

  Print this page

1.用连接池连接数据库的问题 Copy to clipboard
Posted by: shgshg
Posted on: 2006-06-15 13:44

我连接数据库用的是连接池,当用到这句:con = pools.getConnection(); 就没有往下运行了,不知道哪里配置有问题,我的server.xml都是设置好了,设置的情况为: <Context path="/abrs" docBase="abrs" debug="0"
reloadable="true" crossContext="true">
<Logger className="org.apache.catalina.logger.FileLogger"
directory="logs" prefix="localhost_abrs_log." suffix=".txt"
timestamp="true"/>  
<Environment name="maxExemptions" type="java.lang.Integer"
value="100"/>
<Parameter name="context.param.name" value="context.param.value"
override="false"/>

<Resource name="jdbc/abrs" auth="Container"
type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/abrs">


<parameter><name>removeAbandoned</name><value>true</value></parameter>
<parameter><name>removeAbandonedTimeout</name><value>600</value></parameter>
<parameter><name>logAbandoned</name><value>true</value></parameter>
<parameter><name>maxWait</name><value>500</value></parameter>
<parameter><name>maxActive</name><value>50</value></parameter>
<parameter><name>maxIdle</name><value>20</value></parameter>


<parameter><name>username</name><value>sa</value></parameter>
<parameter><name>password</name><value></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=bbs;User=sa;Password=</value>
</parameter>
</ResourceParams>
<Resource name="mail/Session" auth="Container"
type="javax.mail.Session"/>
<ResourceParams name="mail/Session">
<parameter>
<name>mail.smtp.host</name>
<value>localhost</value>
</parameter>
</ResourceParams>
<ResourceLink name="linkToGlobalResource"
global="simpleValue"
type="java.lang.Integer"/>
</Context>
应该没有问题的,连接池的部门代码:
initCtx = new InitialContext();

pools = (DataSource)initCtx.lookup("java:comp/env/jdbc/abrs");
。。。。
DataSource pools = tds.getDataSource();
con = pools.getConnection();运行到这里就运行不下去,请高手指点?

2.Re:用连接池连接数据库的问题 [Re: shgshg] Copy to clipboard
Posted by: shgshg
Posted on: 2006-06-15 17:49

用断点跟踪的时候显示找不到 BasicDataSource.createDataSource() 行,可能就是无法调用:
initCtx = new InitialContext();

pools = (DataSource)initCtx.lookup("java:comp/env/jdbc/abrs");
是不是啊?如果是的话我配置在那里应该做相应的调整???


   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