问题出在哪儿?急死人!

05-03-27 huchg

我想在tomcat5.5中利用数据源实现安全验证,于是按照彭老师书上所说在conf\server.xml的<GlobalNamingResources>中加入如下内容:

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

<ResourceParams name="jdbc/test">

<parameter>

<name>factory</name>

<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>

</parameter>

<parameter>

<name>maxActive</name>

<value>100</value>

</parameter>

<parameter>

<name>maxIdle</name>

<value>30</value>

</parameter>

<parameter>

<name>maxWait</name>

<value>10000</value>

</parameter>

<parameter>

<name>username</name>

<value>test</value>

</parameter>

<parameter>

<name>password</name>

<value>test</value>

</parameter>

<parameter>

<name>driverClassName</name>

<value>com.mysql.jdbc.Driver</value>

</parameter>

<parameter>

<name>url</name>

<value>jdbc:mysql://localhost/test</value>

</parameter>

</ResourceParams>

并在server.xml的<Engine name="Catalina" defaultHost="localhost">中加入:

<Realm className="org.apache.catalina.realm.DataSourceRealm" debug="99"

dataSourceName="jdbc/test"

userTable="users" userNameCol="username" userCredCol="password"

userRoleTable="userrole" roleNameCol="rolename"/>

我使用的是mysql数据库,已经将mysql的jdbc驱动程序包放置在tomcat的common/lib下,并设置好了web.xml,以实现用户登录的安全验证。奇怪的是,系统总是说:

2005-3-26 10:45:44 org.apache.catalina.realm.DataSourceRealm open

严重: Exception performing authentication

org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'

at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:780)

at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)

at org.apache.catalina.realm.DataSourceRealm.open(DataSourceRealm.java:394)

at org.apache.catalina.realm.DataSourceRealm.getPassword(DataSourceRealm.java:419)

at org.apache.catalina.realm.RealmBase.getDigest(RealmBase.java:1083)

at org.apache.catalina.realm.RealmBase.authenticate(RealmBase.java:336)

at org.apache.catalina.authenticator.DigestAuthenticator.findPrincipal(DigestAuthenticator.java:280)

at org.apache.catalina.authenticator.DigestAuthenticator.authenticate(DigestAuthenticator.java:175)

at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:446)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)

at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:307)

at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:385)

at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:748)

at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:678)

at org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:871)

at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)

at java.lang.Thread.run(Unknown Source)

Caused by: java.sql.SQLException: No suitable driver

at java.sql.DriverManager.getDriver(Unknown Source)

at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:773)

意思似乎是mysql的驱动程序有问题。但是,如果我使用JDBCRealm,则可以成功实现用户登录安全验证,说明mysql的JDBC驱动没有问题(3.1.7版本)。为什么使用DataSourceRealm就不能成功???我还按照书上说的将commons-dbcp-1.2.1.jar、commons-pool-1.2.jar、commons-collections-3.1.jar放到tomcat的common/lib下,还是不行!

各位大侠!帮帮我吧!

yubaojian0616
2005-03-27 18:08

你的mysql的驱动没有添加正确阿

自己看看自己添加的驱动程序是什么包下的什么类阿