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 (
At Org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection (
At Test. Testserverlet.service (
At Javax.servlet.http.HttpServlet.service (
At Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (
At Org.apache.catalina.core.ApplicationFilterChain.doFilter (
At Org.apache.catalina.core.StandardWrapperValve.invoke (
At Org.apache.catalina.core.StandardContextValve.invoke (
At Org.apache.catalina.core.StandardHostValve.invoke (
At Org.apache.catalina.valves.ErrorReportValve.invoke (
At Org.apache.catalina.core.StandardEngineValve.invoke (
At Org.apache.catalina.connector.CoyoteAdapter.service (
At Org.apache.coyote.http11.Http11Processor.process (
At Org.apache.coyote.http11.http11baseprotocol$http11connectionhandler.processconnection (
At (
At (
At Org.apache.tomcat.util.threads.threadpool$ (
At (
caused by:java.sql.SQLException:No suitable driver
At Java.sql.DriverManager.getDriver (
At Org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource (
... 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

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"

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.


<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://" Xmlns:xsi= "Http://" xsi:schemalocation= "Http:// http :// "> <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.

Package test; Import; Import; 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 ( ()) {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: 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.