开发者

java web app run in netbeans - SQLException: No suitable driver

I am trying to run an application developed on another machine where it was perfectly running, so it should have something to do with the configurations on the machine I am trying to run it on now. I'm using netbeans 6.9, tomcat 6.0.26 and maven.

When I try to run it, it gives me the following error:

Sep 19, 2010 12:51:02 AM org.hibernate.cfg.SettingsFactory buildSettings
WARNING: Could not obtain connection metadata
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class 'com.mysql.jdbc.Driver' for connect URL 'http://maven.apache.org'
    at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1150)
    at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
    at org.hibernate.connection.DatasourceConnectionProvider.getConnection(DatasourceConnectionProvider.java:69)
    at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:84)
    at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2073)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1298)
    at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
    at AppConfiguration.loadConfig(AppConfiguration.java:164)
    at Listener.contextInitialized(Listener.java:40)
    at Org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3972)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4467)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546)
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:637)
    at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:563)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:498)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1277)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
    at org.apache.catalina.core.StandardService.start(StandardService.java:519)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.sql.SQLException: No suitable driver
    at java.sql.DriverManager.getDriver(DriverManager.java:264)
    at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1143)
    ... 32 more

I should mention that:

1 I have mysql-connector-java-5.1.13-bin.jar in Apache Tomcat 6.0.26\lib and in my pom.xml I have:

      <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <url>http://maven.apache.org</url>

and

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.13</version>
    <scope>provided</scope>
</dependency>

2 I have the jar in my local maven repository.

3 Netbeans seems to come now with 'embedded maven version 3.0', which is a beta version. So I've configured it to use as External Maven Home: C:\Program Files\apache-maven-2.2.1. Running mvn --version gives the correct version, so maven 2.2.1 seems to be properly installed on my system. But for some reason, whenever I run the app, I also get this:

WARNING: You are running embedded Maven builds, some build may fail due to     incompatibilities with latest Maven release. To set Maven instance to use for building, click here.

The build does not fail, but the link that the above warning points me to, gets me to the same window where I've already configured 'External Maven Home', as mentioned above.

4 Adding DriverManager.registerDriver(new com.mysql.jdbc.Driver()); (as seen in another post here on stackoverflow) before anything related to the database did not help.

5 The same code was running on another machine.

I would appreciate any ideas as to why I am getting the jdbc driver error. And please keep in mind that the application was running on another machine.

context.xml:

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/app/test">
  <Resource auth="Container" defaultAutoCommit="false" description="dbcp" driverClassName="com.mysql.jdbc.Driver" initialSize="1" maxActive="10" maxIdle="5" maxWait="1000" minIdle="10" name="jdbc/Test" password="${database.password}" poolPreparedStatements="true" type="javax.sql.DataSource" url="${database.url}" username="${database.username}"/>
  <Realm className="org.apache.catalina.realm.DataSourceRealm" dataSourceName="jdbc/Test" localDataSource="true" roleNameCol="role" userCredCol="pass" userNameCol="user" userRoleTable="roles" userTable="users"/>
  <Valve className="org.apache.catalina.valves.AccessLogValve" fileDateFormat="yyyy-MM-dd" pattern="combined" prefix="test-access" resolveHosts="false" rotatable="true" suffix=".log"/>
</Context>

where database.url is jdbc:mysql://127.0.0.1:3306/test?autoReconnect=true

hibernate.cfg.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="connection.datasource">java:/comp/e开发者_运维问答nv/jdbc/Test</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
        <property name="cache.use_query_cache">false</property>
        <property name="cache.use_minimal_puts">false</property>
        <property name="max_fetch_depth">3</property>
        <property name="show_sql">true</property>
        <property name="format_sql">true</property>
        <property name="generate_statistics">true</property>
        <property name="hbm2ddl.auto">validate</property>
        <property name="current_session_context_class">thread</property>
        <mapping class="Test.Users"/>
        <mapping class="Test.Roles"/>
        <!-- entity bean defs -->
    </session-factory>
</hibernate-configuration>


Common causes for java.sql.SQLException: No suitable driver are

  • the URL is wrong
  • followed by the driver isn't loaded.

And indeed, the following line clearly indicates something wrong.

Cannot create JDBC driver of class 'com.mysql.jdbc.Driver' for connect URL 'http://maven.apache.org'

The JDBC connection string can't be http://maven.apache.org.

Check your build, something IS wrong (it looks like some unexpected filtering is occurring).

But you're not giving enough details for a more detailed answer.


This looks like you have told Hibernate to use a container provided DataSource, which in turn cannot locate the JDBC-driver.

If so, the problem is that code loaded by the container class loader cannot see code provided in your WAR .

You must add the driver jar to the extension folder of the container.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜