简体   繁体   English

无法一直为连接URL'null创建类''的JDBC驱动程序

[英]Cannot create JDBC driver of class '' for connect URL 'null all the time

Hello I have following problem: Whenever I try to connect to MySQL DB I get this error: 您好,我遇到以下问题:每当我尝试连接到MySQL DB时,都会出现此错误:

com.pbs.web.jdbc.ParkingBookSystem.BookControllerServlet doGet
SEVERE: null
**java.sql.SQLException: Cannot create JDBC driver of class '' for connect URL 'null'**
    at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory(BasicDataSource.java:2224)
    at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:2104)
    at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1563)
    at com.pbs.web.jdbc.ParkingBookSystem.BookDbUtil.doesBookExist(BookDbUtil.java:91)
    at com.pbs.web.jdbc.ParkingBookSystem.BookControllerServlet.addBook(BookControllerServlet.java:117)
    at com.pbs.web.jdbc.ParkingBookSystem.BookControllerServlet.doGet(BookControllerServlet.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:668)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:770)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    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.dbcp2.BasicDataSource.createConnectionFactory(BasicDataSource.java:2209)
    ... 29 more

I have context.xml placed in the the: C:\\Users\\userName\\eclipse-workspace\\WebAppName\\src\\main\\resources\\META-INF Here is the code: 我将context.xml放在以下位置:C:\\ Users \\ userName \\ eclipse-workspace \\ WebAppName \\ src \\ main \\ resources \\ META-INF这是代码:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<Context>
<Resource 
    name="ParkingBookSystem" 
    auth="Container"
    type="javax.sql.DataSource"
    maxTotal="20"
    maxIdle="5"
    maxWaitMillis="10000"
    username="sql2226123"
    password="cccccccc"
    driverClassName="com.mysql.jdbc.Driver"
    url="jdbc:mysql://sql2.freemysqlhosting.net:3306/sql2226123"
/>
</Context>

and my web.xml (placed at C:\\Users\\userName\\eclipse-workspace\\WebAppName\\src\\main\\webapp\\WEB-INF ): 和我的web.xml(放在C:\\ Users \\ userName \\ eclipse-workspace \\ WebAppName \\ src \\ main \\ webapp \\ WEB-INF):

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<description>ParkingBookSystem</description>
<resource-ref>
    <description>DB Connection</description>
    <res-ref-name>/ParkingBookSystem</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>
<welcome-file-list>
    <welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>

Here is my class constructor to make DB connection: 这是我建立数据库连接的类构造函数:

// constructor
public BookDbUtil() {
    try {
        Context initContext = new InitialContext();
        Context envContext = (Context) initContext.lookup("java:/comp/env");
        dataSource = (DataSource) envContext.lookup("ParkingBookSystem");
    } catch (NamingException e) {
        throw new IllegalStateException("Could not initialize database", e);
    }
}

I'm using Maven, Eclipse and Tomcat this is what I've tried so far: 我正在使用Maven,Eclipse和Tomcat,这是我到目前为止已经尝试的方法:

  • I put the mysql-connector-java-5.1.38-bin to the tomcat lib 我将mysql-connector-java-5.1.38-bin放入tomcat库
  • Manualy put the context.xml to C:\\Program Files\\Apache Software Foundation\\Tomcat 9.0\\conf\\Catalina\\localhost 手动将context.xml放入C:\\ Program Files \\ Apache Software Foundation \\ Tomcat 9.0 \\ conf \\ Catalina \\ localhost
  • as above but changed name from context.xml to projectName.xml 如上,但名称从context.xml更改为projectName.xml
  • Put all content into the server.xml (and commented out default resource what was here) 将所有内容放入server.xml(并注释掉默认资源)
  • I found also that evey change in tomcat files need admin previleage so I added full controll for each user to make sure that is not the case. 我还发现,tomcat文件中的evey更改需要管理员预先管理,因此我为每个用户添加了完全控制权,以确保情况并非如此。

I have no more ideas, any one is able to help? 我没有更多的想法了,有谁能提供帮助?

please; 请;

put the mysql connector jar file in WEB-INF/lib directory 将mysql连接器jar文件放在WEB-INF / lib目录中

and change in the context.xml 并更改context.xml

<Context>
    <Resource name="jdbc/ParkingBookSystem" ...

and change in the web.xml 并更改web.xml

<res-ref-name>jdbc/ParkingBookSystem</res-ref-name>

and change lookup 并更改查找

Context initContext = new InitialContext();
Context envContext  = (Context)initContext.lookup("java:/comp/env");
dataSource = (DataSource)envContext.lookup("jdbc/ParkingBookSystem");

好的,我找到了解决方案...问题是我的带有context.xml的META-INF位于C:\\ Users \\ lukas \\ eclipse-workspace \\ ParkingBookSystem \\ src \\ main \\ resources \\ META-INF \\ context.xml中进入:C:\\ Users \\ lukas \\ eclipse-workspace \\ ParkingBookSystem \\ src \\ main \\ webapp,它开始工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 带有mysql的Tomcat:“无法为连接URL&#39;null&#39;创建类”的JDBC驱动程序” - Tomcat with mysql : “ Cannot create JDBC driver of class '' for connect URL 'null' ” 无法为连接URL&#39;null&#39;Oracle创建类&#39;&#39;的JDBC驱动程序 - Cannot create JDBC driver of class '' for connect URL 'null' Oracle 无法为连接URL&#39;null&#39;和NullPointerException创建类&#39;&#39;的JDBC驱动程序 - Cannot create JDBC driver of class '' for connect URL 'null' and NullPointerException 无法创建 class“”的 JDBC 驱动程序用于连接 URL 'null' - Cannot create JDBC driver of class “” for connect URL 'null' 无法为连接URL''创建类''的JDBC驱动程序 - Cannot create JDBC driver of class '' for connect URL 'null' 无法为连接URL null创建类的JDBC驱动程序 - Cannot create JDBC driver of class for connect URL null 无法为连接URL&#39;null&#39;创建类&#39;&#39;的JDBC驱动程序:Tomcat和SQL Server JDBC驱动程序 - Cannot create JDBC driver of class '' for connect URL 'null' : Tomcat & SQL Server JDBC driver 无法为连接 URL 的 class '' 创建 JDBC 驱动程序 - Cannot create JDBC driver of class '' for connect URL 在tomcat 6中创建和使用数据源时,无法为连接URL&#39;null&#39;-:ERROR创建类&#39;&#39;的JDBC驱动程序 - Cannot create JDBC driver of class '' for connect URL 'null' -:ERROR while creating and using a Datasource in tomcat 6 无法为连接URL&#39;null&#39;创建类&#39;&#39;的JDBC驱动程序:Tomcat + MySQL + Spring MVC - Cannot create JDBC driver of class '' for connect URL 'null' : Tomcat + MySQL + Spring MVC
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM