【发布时间】:2016-11-28 23:49:12
【问题描述】:
我正在尝试使用 jndi 查找建立与数据库的连接
这是我在 webapp meta-inf 文件夹中定义的 context.xml
<Resource name="jdbc/connectDB" auth="Container" type="javax.sql.DataSource"
maxTotal="100" maxIdle="30" maxWaitMillis="10000" username="root"
password="" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/connect" />
我正在使用这个过程在 web.xml 文件夹中调用它
<resource-ref>
<res-ref-name>jdbc/connectDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
在研究解决错误后,我还尝试使用 webappname.xml 引用我的 catalina 文件夹中的文件。我还在tomcat的lib文件夹中添加了jar,但错误仍然存在。
这是错误跟踪
SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/connectmain] threw exception [Request processing failed; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Cannot create JDBC driver of class '' for connect URL 'null'] with root cause
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(DriverManager.java:315)
请问我错过了什么才能得到这个错误
【问题讨论】:
-
你的代码如何使用这个资源,你能添加那部分吗?
-
我在注册时使用它
标签: java mysql spring tomcat jndi