0

I am trying to connect to mysql database. I am using MySQL workbench. These are my codes:

 Class.forName("com.mysql.jdbc.Driver");
 con =DriverManager.getConnection("jdbc:mysql://localhost/try?" +"user=jenny&password=perez");

 PreparedStatement ps=con.prepareStatement("SELECT * FROM address");
 ResultSet myRS=ps.executeQuery();

What's wrong with my codes?

2
  • Because you don't have the MySQL JDBC driver on the app's classpath? Commented Jan 13, 2015 at 2:22
  • Have you added the JDBC driver to your classpath? Commented Jan 13, 2015 at 2:22

1 Answer 1

1

Your codes are correct. You come up with that error because you have no mysql connector. Try to download mysql-connector-java-5.1.18-bin. Install it here C:\Program Files\Java\jre6\lib. Then, Go to the properties of your project, then follow these:

Go to Libraries, then Compile, click Add JAR/Folder, then search the mysql connector you installed. Then run your program. ^_^

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

1 Comment

Could you possibly name a version that isn't several years out of date? The current version is 5.1.34.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.