aaberg / sql2o

sql2o is a small library, which makes it easy to convert the result of your sql-statements into objects. No resultset hacking required. Kind of like an orm, but without the sql-generation capabilities. Supports named parameters.
http://sql2o.org
MIT License
1.15k stars 229 forks source link

No suitable driver found for... #294

Closed Lumos-Nox closed 6 years ago

Lumos-Nox commented 6 years ago

Hi, I'm using tomcat and sql2o to develop web application, but sql2o could not load mysql-connector-java-5.1.23-bin.jar in $CATALINA_HOME/lib, only when this jar file was placed in /Library/Java/Extensions/ directory did it work. Besides, using java native library to require a data source also works. Thanks in advance.

klaushauschild1984 commented 6 years ago

Such problems will mostly not caused by the applications and its libraries. In most cases it is a problem at the setup. So please double and tripple check your setup. Maybe you can provide more details.

Lumos-Nox commented 6 years ago

@klaushauschild1984 Thanks for your comment. Let me make it clearer....

Brief preview of my project

The setup of the project needs the following JAR files:

The first case (Success):

If I put all JAR files mentioned above in /Library/Java/Extensions, then compile and
build the project, and restart tomcat and run the web application, everything works
fine.

The second case (Success):

If I keep mysql-connector-java-5.1.23-bin.jar in /Library/Java/Extensions, but other
JAR files are moved to $CATALINA_HOME/lib, and repeat the above steps in the first
case, everything works fine again!

The third case (Failed):

If I do the same thing in the second case except that the
mysql-connector-java-5.1.23-bin.jar is moved to $CATALINA_HOME/lib, an error
(500 - Internal Server Error) happens. [Root Cause is: java.sql.SQLException:
No suitable driver].

The fourth case (Success):

I have developed a web application using servlet but import java.sql.* rather than
org.sql2o.*, also mysql-connector-java-5.1.23-bin.jar is moved to $CATALINA_HOME/lib,
but this time the web application works correctly as it should do.

I have explained the setup thoroughly, now it is your turn. :-) Thanks again. dofadore

zapodot commented 6 years ago

@Lumos-Nox I do understand that you have an issue, but it has to do with Tomcat and how third-party libraries are added to it. Please consult the Tomcat Classloading guide at https://tomcat.apache.org/tomcat-9.0-doc/class-loader-howto.html Having said that, adding libraries to the system Java runtime is generally considered to be a bad idea as it makes your application less portable. Usually, database drivers are provided by the application server (i.e Tomcat) or bundled with your application (for instance in the WEB-INF/lib folder of a WAR file). Closing this issue now