Home > Coding > java.sql.SQLException: No suitable driver

java.sql.SQLException: No suitable driver

October 10th, 2007 Leave a comment Go to comments

After trying to set up Maven2 with Spring 2, Hibernate 3 (with annotations) I tried to configure the maven2 hibernate3 plugin so the schema could be exported for manual creation.

Then it hit me, a:

java.sql.SQLException: No suitable driver

I didn’t get this one before when using XDoclet2 to generate the hbm.xml files and schema-export for me. I did some research on the net and found out that the calling program is verifying the jdbc url against all available drivers. When none of the drivers accepts the jdbc url the above error is thrown. It’s good to know that the jdbc drivers are loaded dynamically.

Knowing this solved the puzzle: Either the jdbc url was not ok or the driver was not loaded at the point of the schema-export. The latter was the case. By adding the jdbc jar to the classpath I could luckily fix this issue. Maybe I should have done so in the first place. Well at least I learned something from all this and I hope you will too by reading this.

Here is a small snippet of my pom.xml for maven2. The db-properties are read from the META-INF/persistence.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<!-- Hibernate3 Plugin, used for creating SQL statements for table creation -->
<plugin>
	<groupid>org.codehaus.mojo</groupid>
	<artifactid>hibernate3-maven-plugin</artifactid>
	<version>2.0-SNAPSHOT</version>
	<configuration>
		<executions>
			<execution>
				<phase>process-classes</phase>
				<goals>
					<goal>hbm2ddl</goal>
				</goals>
			</execution>
		</executions>
		<components>
			<component>
				<name>hbm2ddl</name>
			</component>
		</components>
		<componentproperties>
			<implementation>jpaconfiguration</implementation>
			<!-- Output in pretty format -->
			<format>true</format>
			<!-- Do not create drop statements -->
			<drop>false</drop>
			<!-- Generate script -->
			<text>true</text>
			<!-- Do not output sql to screen -->
			<quiet>false</quiet>
			<!-- Do not export tables into database -->
			<export>false</export>
			<outputfilename>
				schema-export.sql
			</outputfilename>
		</componentproperties>
	</configuration>
	<dependencies>
		<!-- Necessary to be able to connect to db -->
		<dependency>
			<groupid>local</groupid>
			<artifactid>oracle-classes</artifactid>
			<version>1.2</version>
		</dependency>
	</dependencies>
</plugin>
Categories: Coding Tags:
  1. May 23rd, 2008 at 02:22 | #1

    dude, this post is exactly what i was looking for. all the effin mojo site docs don’t let on that you have to have the *and* configured for the to work. thanks mucho

  2. Wytze
    May 23rd, 2008 at 08:02 | #2

    Glad I could be of assistance. 😉

  1. No trackbacks yet.

Time limit is exhausted. Please reload CAPTCHA.