views:

1760

answers:

3

Hello,

I am new to creating Java web applications and came across this problem when trying to interact with my database (called ccdb) through my application:

java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost/ccdb/

My application runs on JBoss and uses Hibernate to interact with the MySQL database. I have the MySQL Driver in lib\mysql-connector-java-5.1.6-bin.jar of my project and I have the .jar configured in Eclipse as a "Java EE Module Dependency" so that it gets copied over to web-inf\lib\ when I deploy it to JBoss through Eclipse. I double checked and the driver is definitely in the .war file with the project, so it should be findable, right?

My hibernate.cfg.xml contains this line which should point hibernate to the driver.

<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>

Does anyone know what I need to do to get this to work? Do I have to configure the MySQL database as a JBoss datasource for it to work?

Thanks in advance.

Edit: kauppi's solution works, but I would prefer to have it in lib\ with the other jars, and I'm really curious as to why it won't work that way. Any ideas...?

+2  A: 

There might be a better way to do it but I have usually copied the MySQL connector JAR to jboss\server\default\lib (assuming that you are using the default config).

kauppi
Thanks, that works, but I was hoping to find a way to keep it in /lib and am really curious as to why it won't work that way.
spadequack
+3  A: 

putting external libraries in the lib folder is a bad practice.

You need to edit the file:

server/${servername}/conf/jboss-service.xml and add

<classpath codebase="${jboss.server.lib.url:lib}ext" archives="*"/>

rigth after

<classpath codebase="${jboss.server.lib.url:lib}" archives="*"/>

then create a directory named: server/${servername}/lib/ext

and drop your external jars in there.

feniix
+1  A: 

God bless you feniix. thanks so much.