Cannot create JDBC driver of class ' for connect URL ' null '

Source: Internet
Author: User
Tags auth xmlns tomcat

Today, tomcat5.528. Configure the data source connection pool, configure it on the Tomcat admin interface, write a Serverlet test, and report a cannot create JDBC driver of class ' for connect URL ' null ' ERROR,

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:1150)
At Org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection (basicdatasource.java:880)
At Test. Testserverlet.service (testserverlet.java:29)
At Javax.servlet.http.HttpServlet.service (httpservlet.java:729)
At Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (applicationfilterchain.java:269)
At Org.apache.catalina.core.ApplicationFilterChain.doFilter (applicationfilterchain.java:188)
At Org.apache.catalina.core.StandardWrapperValve.invoke (standardwrappervalve.java:213)
At Org.apache.catalina.core.StandardContextValve.invoke (standardcontextvalve.java:172)
At Org.apache.catalina.core.StandardHostValve.invoke (standardhostvalve.java:127)
At Org.apache.catalina.valves.ErrorReportValve.invoke (errorreportvalve.java:117)
At Org.apache.catalina.core.StandardEngineValve.invoke (standardenginevalve.java:108)
At Org.apache.catalina.connector.CoyoteAdapter.service (coyoteadapter.java:174)
At Org.apache.coyote.http11.Http11Processor.process (http11processor.java:873)
At Org.apache.coyote.http11.http11baseprotocol$http11connectionhandler.processconnection ( http11baseprotocol.java:665)
At Org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket (pooltcpendpoint.java:528)
At Org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt (leaderfollowerworkerthread.java:81)
At Org.apache.tomcat.util.threads.threadpool$controlrunnable.run (threadpool.java:689)
At Java.lang.Thread.run (thread.java:595)
caused by:java.sql.SQLException:No suitable driver
At Java.sql.DriverManager.getDriver (drivermanager.java:243)
At Org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource (basicdatasource.java:1143)
... More

, in a search on the internet, all said 5.5 with errors, and some said that the version did not appear this wrong, I feel sure is where the configuration is not correct, not the version is not supported, Java.sql.SQLException:No suitable driver
See this paragraph still wrong to think is the driver version of MySQL is wrong, and another one or the same, and later found on the internet a person said, "and then in the WebApp context.xml add" Here configuration, I looked for a bit context.xml this file open a look

<resource
Auth= "Container"
description= "Dmst"
Name= "Jdbc/dmst"
Type= "Javax.sql.DataSource"
Driverclassname= ""
/>

My gut tells me the problem is here. Driverclassname= "" Here is not "", the error is not to say cannot create JDBC driver of class ' for connect URL ' null ';d riverclass is empty, The URL is null; so I put driverclassname= "Com.mysql.jdbc.Driver"
Url= "JDBC:MYSQL://LOCALHOST:3306/QXXT?USEUNICODE=TRUE&AMP;CHARACTERENCODING=GBK" These two words plus go, restart, haha

Visit Serverlet, haha, the wrong finally did not, but still wrong is said to prevent me to connect to the database, a look at it is the user name does not, and then add the user name password, all OK

All right, I'm going to send out the entire code.

%tomcat_home%/conf/server.xml

<resource name= "Jdbc/dmst" type= "Javax.sql.DataSource" driverclassname= "Com.mysql.jdbc.Driver" password= "root" Maxidle= "2" maxwait= "username=" root "url=" jdbc:mysql://localhost:3306/qxxt?useunicode=true& CHARACTERENCODING=GBK "maxactive=" 4 "/>

The key to the issue, the other will not send it.

Web. XML for the WebApp project

<?xml version= "1.0" encoding= "UTF-8"?> <web-app version= "2.5" xmlns= "Http://java.sun.com/xml/ns/javaee" Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee http ://java.sun.com/xml/ns/javaee/web-app_2_5.xsd "> <servlet> <description>this is the description of my Java EE component</description> <display-name>this is the display name of my EE component</display-name > <servlet-name>TreeServerlet</servlet-name> <servlet-class> Com.pmsm.serverlet.treeserverlet</servlet-class> </servlet> <servlet> <description>this is The description of my EE component</description> <display-name>this is the display name of my my EE component </display-name> <servlet-name>TestServerlet</servlet-name> <servlet-class>test. testserverlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>treeserverlet </servleT-name> <url-pattern>/servlet/treeServerlet</url-pattern> </servlet-mapping> < Servlet-mapping> <servlet-name>TestServerlet</servlet-name> <url-pattern>/servlet/ testserverlet</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file> index.jsp</welcome-file> </welcome-file-list> <resource-ref> <description>dmst</ Description> <res-ref-name>jdbc/dmst</res-ref-name> <res-type>javax.sql.datasource</ res-type> <res-auth>Container</res-auth> </resource-ref> </web-app>

My test serverlet here is Testserverlet.

Testserverlet.java

Package test; Import java.io.IOException; Import Java.io.PrintWriter; Import java.sql.Connection; Import java.sql.PreparedStatement; Import Java.sql.ResultSet; Import java.sql.SQLException; Import java.sql.Statement; Import Javax.naming.InitialContext; Import javax.naming.NamingException; Import javax.servlet.ServletException; Import Javax.servlet.http.HttpServlet; Import Javax.servlet.http.HttpServletRequest; Import Javax.servlet.http.HttpServletResponse; Import Javax.sql.DataSource; public class Testserverlet extends HttpServlet {@Override protected void service (HttpServletRequest arg0, Httpservletres Ponse arg1) throws Servletexception, IOException {DataSource ds = null; try {initialcontext ctx = new InitialContext (); ds = (DataSource) ctx.lookup ("Java:comp/env/jdbc/dmst"); Connection conn = Ds.getconnection (); PreparedStatement ps=conn.preparestatement ("SELECT * from Sm_user"); ResultSet Rs=ps.executequery (); while (Rs.next ()) {System.out.println (rs.getstring (1) + "," +rs.getstring (2)); } rs.close (); Ps.close (); Conn.close (); } catch (Namingexception e) {//Todo auto-generated catch Block E.printstacktrace ()} catch (SQLException e) {//Todo A Uto-generated Catch block E.printstacktrace (); } } }

Key areas:

webapps/Project Name/meta-inf/context.xml

<?xml version= "1.0" encoding= "UTF-8"?> <Context> <listener classname= " Org.apache.catalina.startup.TldConfig "/> <listener classname=" Org.apache.catalina.startup.TldConfig "/> <listener classname= "Org.apache.catalina.startup.TldConfig"/> <listener classname= " Org.apache.catalina.startup.TldConfig "/> <resource auth=" Container "description=" Dmst "name=" Jdbc/dmst " password= "root" username= "root" type= "Javax.sql.DataSource" driverclassname= "Com.mysql.jdbc.Driver" url= "JDBC: MYSQL://LOCALHOST:3306/QXXT?USEUNICODE=TRUE&CHARACTERENCODING=GBK "</Context>

OK test go, everything's OK.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.