0

Ok I am trying to connect to a mysql db with the following code. I tried looking at documentation but I am just having no luck what so ever.

Here is the code:

public class TESTSQL { static final String JDBC_DRIVER = "com.mysql.jdbc.Driver"; static final String DB_URL = "jdbc:mysql://SLibraryDev.db.996****.hostedresource.com"; static final String USER = "SLD"; static final String PASS = "F11!"; public static void main(String[] args) { Connection conn = null; Statement stmt = null; try { // STEP 2: Register JDBC driver Class.forName(JDBC_DRIVER); // STEP 3: Open a connection System.out.println("Connecting to database..."); conn = DriverManager.getConnection(DB_URL, USER, PASS); ... } 

This is the error I am getting :

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver at java.net.URLClassLoader$1.run(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source) 

When I comment out "Class.forName(JDBC_DRIVER)" and run it I get this error:

java.sql.SQLException: No suitable driver found for jdbc:mysql://SLibraryDev.db.996****.hostedresource.com at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) 

What I thought I needed to do was to download and run this : http://dev.mysql.com/downloads/connector/j/ which I did but it seemed like something was wrong with this installer...It seemed like it never finished, like it cut out in the middle of the process. Anyone have any ideas on what I need to do.

1
  • You've got to add the ConnectorJ jar library to your project classpath. Commented Feb 6, 2013 at 5:40

3 Answers 3

1

Download mysql-connector from following url http://nearbuy.googlecode.com/files/mysql-connector-java-5.1.13-bin.jar

and add it to your class path.

If you are using netbeans, to add this file to your project do followoing

Right click on your project>click libraries>click add JAR/Folder> then select downloaded jar file

Sign up to request clarification or add additional context in comments.

Comments

0

You need to download the mysql jdbc driver jar and include it in your classpath

Comments

0
java.sql.SQLException: No suitable driver found for jdbc:mysql://SLibraryDev.db.996****.hostedresource.com at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) 

clearly suggests that there is no driver in your class path

simply add the mysql driver jar file in to class path

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.