gpt4 book ai didi

java - 找不到 TomEE 数据源

转载 作者:行者123 更新时间:2023-12-02 04:38:47 28 4
gpt4 key购买 nike

我有一个关于 TomEE 和使用 tomee.xml 中指定的数据源的奇怪问题。值得注意的是,我使用的是 Netbeans、TomEE 和 MySQL。在 Ubuntu 13.04(Xubuntu 最新)上运行

tomee.xml文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<tomee>
<Resource id="booktablesDS" type="DataSource">
JdbcDriver com.mysql.jdbc.Driver
JdbcUrl jdbc:mysql:localhost:3306/book_tables
UserName juser
Password jpassword
JtaManaged true
</Resource>
</tomee>

还有一个小代码片段,测试连接池:

@Resource DataSource booktablesDS;

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {

Connection c = booktablesDS.getConnection();
Statement stmt = c.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM BOOKS");

我从 TomEE 得到的输出是:

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

完整的堆栈跟踪如下。

May 06, 2013 11:08:53 AM org.apache.catalina.util.LifecycleBase start
INFO: The start() method was called on component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/EJBTest]] after start() had already been called. The second call will be ignored.
May 06, 2013 11:08:54 AM MainS processRequest
SEVERE: null
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1452)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
at MainS.processRequest(MainS.java:35)
at MainS.doGet(MainS.java:64)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.NullPointerException
at sun.jdbc.odbc.JdbcOdbcDriver.getProtocol(JdbcOdbcDriver.java:524)
at sun.jdbc.odbc.JdbcOdbcDriver.knownURL(JdbcOdbcDriver.java:493)
at sun.jdbc.odbc.JdbcOdbcDriver.acceptsURL(JdbcOdbcDriver.java:307)
at java.sql.DriverManager.getDriver(DriverManager.java:273)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437)
... 22 more

May 06, 2013 11:08:55 AM org.apache.catalina.startup.HostConfig deleteRedeployResources
INFO: Undeploying context [/EJBTest]

基本上感觉就像 netbeans 正在使用另一个 tomee.xml 文件部署项目?忽略位于 tom-ee/conf/tomee.xml 下的 Tomee.xml 中的值

帮助会很棒。

最佳答案

您的网址似乎有误。

jdbc:mysql:localhost:3306/book_tables

应该是

jdbc:mysql://localhost:3306/book_tables

您能否仔细检查一下 MySQL 驱动程序 JAR 是否确实存在于 tomee/lib 文件夹中。

关于java - 找不到 TomEE 数据源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16395593/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com