Ascendant
Ascendant

Reputation: 827

I have the driver, class.forname() doesn't throw exception but 'No Suitable Driver for MySQL '

I know this kind of question pop up a lot but I needed to ask this question.

I have the jar file containing mysql jdbc driver , namely mysql-connector-java-5.1.12-bin.jar.
I opened this jar file and confirmed that this jar file does contain com.mysql.jdbc.Connection.class.

Class.forName("com.mysql.jdbc.Connection");

This does not throw any exceptions.

When I try to get a connection with the code below however I get an exception.

con = DriverManager.getConnection(dbURL,dbUNM,dbUPW);

(I'm not sure if it's wise to put the connection URL uphere)

I get this

java.sql.SQLException: No suitable driver found for jdbc:mysql:xxx....

also I see

    Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
    at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:968)
    at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:624)
    at org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:823)
    at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:794)
    at org.apache.jsp.index_jsp._jspService(index_jsp.java:1134)

Can you point out what I'm doing wrong ? Thank you : )

Upvotes: 1

Views: 456

Answers (1)

Scorpion
Scorpion

Reputation: 3986

You need to load the driver class using Class.forName - try the following line of code

Class.forName("com.mysql.jdbc.Driver");

Upvotes: 6

Related Questions