我无法在Tomcat7中获取数据库连接。我使用oracle linux作为操作系统。以下是我的数据库连接池配置。
server.xml中
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
<Resource name="jdbc/weblogin01"
auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.OracleDriver"
url="${resource.weblogin01.url}"
username="${resource.weblogin01.username}"
password="${resource.weblogin01.password}"
initialSize="2"
maxActive="20"
maxIdle="10"
minIdle="2"
maxWait="-1"
testWhileIdle="true"
timeBetweenEvictionRunsMillis="20000"
validationQuery="select * from dual" />
<Resource name="jdbc/osswebportal"
auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.OracleDriver"
url="${resource.osswebportal.url}"
username="${resource.osswebportal.username}"
password="${resource.osswebportal.password}"
initialSize="1"
maxActive="20"
maxIdle="10"
maxWait="-1"
testWhileIdle="true"
timeBetweenEvictionRunsMillis="60000"
validationQuery="select * from dual" />
的web.xml
<resource-ref>
> <res-ref-name>jdbc/osswebportal</res-ref-name>
> <res-type>javax.sql.DataSource</res-type>
> <res-auth>Container</res-auth>
> <res-sharing-scope>Shareable</res-sharing-scope>
> </resource-ref>
> <resource-ref>
> <res-ref-name>jdbc/weblogin01</res-ref-name>
> <res-type>javax.sql.DataSource</res-type>
> <res-auth>Container</res-auth>
> <res-sharing-scope>Shareable</res-sharing-scope>
> </resource-ref>
context.xml中
<ResourceLink global="jdbc/weblogin01" name="jdbc/weblogin01" type="javax.sql.DataSource"/>
<ResourceLink global="jdbc/osswebportal" name="jdbc/osswebportal" type="javax.sql.DataSource"/>
我还在tomcat的catalina.properties中定义了所有数据库细节
resource.osswebportal.url = JDBC:预言:瘦:@ test.com:1522:GPSP resource.osswebportal.username =用户
resource.osswebportal.password =密码
resource.weblogin01.url = JDBC:预言:瘦:@ TEST2:1522:GSPS resource.weblogin01.username =用户1
resource.weblogin01.password =密码
答案 0 :(得分:0)
将Driver Jar文件放在服务器lib文件夹中,我认为这样可以解决您的问题。