views:

141

answers:

2

hello,

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"&gt;
      <modelVersion>4.0.0</modelVersion>
      <url>http://maven.apache.org&lt;/url&gt;

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"&gt;
<hibernate-configuration>
    <session-factory>
        <property name="connection.datasource">java:/comp/env/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>
+1  A: 

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.

Pascal Thivent
I've seen the two possible causes in other posts, but I don't know how to rule out any of them. Please tell me what more details I should give. The only place where I have that URL is in my pom.xml, this is why I have posted the relevant lines of code from it.
mihaela
@mihaela Where is the jdbc connection string declared? Do you have a `context.xml`? In a `hibernate.cfg.xml`? What's the content (before/ after the build)?
Pascal Thivent
I have now provided these details as an Edit to my original post.
mihaela
@mihaela Where is `database.url` defined? Did you check the "filtered" version of your `context.xml` (after the build)? It looks like it gets the value of `${project.url}`.
Pascal Thivent
Indeed that was the problem. I've now seen that after build, my context.xml does not have database.password, database.user and database.url replaced with the correct values which are found in a .properties file that I am using for switching between development and production configurations. These files seem not to be interpreted and project.url ends up being replaced by http://maven.apache.org. Thank you so much for your time.
mihaela
A: 

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.

Thorbjørn Ravn Andersen
I have mysql-connector-java-5.1.13-bin.jar in Apache Tomcat 6.0.26\lib, if this is what you are referring to.
mihaela
The problem is that DriverManager cannot locate a driver for the JDBC string provided. You should have that covered by point 4 - does the class load?
Thorbjørn Ravn Andersen
The problem is that the JDBC string *is* wrong (it is currently `http://maven.apache.org`). It is not a classloading problem.
Pascal Thivent
It seems that the problem was what Pascal Thivent pointed out, but I appreciate your trying to help me. Thank you.
mihaela
@Pascal, ah. Thought that this message came _after_ the driver had been chosen, not before. How did the MySQL driver get chosen then?
Thorbjørn Ravn Andersen
@Thorbjørn The driver class name is part of the datasource definition. Anyway, errors are really very poorly reported.
Pascal Thivent
Ok, didn't know that about the data source. Agree on the poor reporting.
Thorbjørn Ravn Andersen