user975561
user975561

Reputation: 514

JavaEE MySQL connection: No suitable driver found

I want to establish a connection to my MySQL database from my Java EE web application so I can query it from it. I added mysql-connector-java-5.1.14-bin.jar to my WEB-INF/lib folder.

Now when I try to establish a connection it says:

No suitable driver found for jdbc:mysql://localhost?autoReconnect=true.

The lines in my code where the error occurs are:

m_url = "jdbc:mysql://" + mDatabaseHost +"?autoReconnect=true";
m_connection = DriverManager.getConnection(m_url, mDatabaseUser, mDatabasePassword);

User and password are correct. What might be wrong?

I tested this with Tomcat 7.0.

Upvotes: 1

Views: 594

Answers (2)

Sal
Sal

Reputation: 1238

Try to add the database name after localhost and ensure that you don't have skip-networking in the my.cnf file

UPDATE

Put the Connector Jar into $CATALINA_HOME/lib

Upvotes: 0

AlexR
AlexR

Reputation: 115378

I think that you forgot to initialize driver.

You have to say something like the following: Class.forName("com.mysql.jdbc.Driver"); bofore connecting to DB.

Upvotes: 2

Related Questions