0

I'm trying to connect my Java program to a database using MySQL Java Connector 5.1.8, but I keep having a java.lang.Classnotfound exception: com.sql.jdbc.driver error.

Can someone help me solve this? BTW: I have a 64bit processor.

public static void post(String name) { 
    Connection conn = null; 
    try { 
        String userName = "root"; 
        String password = ""; 
        String url = "jdbc:mysql://localhost/name"; 
        Class.forName ("com.mysql.jdbc.Driver").newInstance(); 
        conn = DriverManager.getConnection(url, userName, password);
        PreparedStatement s; 
        s = conn.prepareStatement ("INSERT INTO input(name1) VALUES(?)"); 
        s.setString(1, name); 
        int count = s.executeUpdate(); 
        s.close(); 
        System.out.println("\n" + count + " rows were inserted"); 
    } catch (Exception e) {
    }
dur
  • 15,689
  • 25
  • 79
  • 125
Victor
  • 9
  • 1
  • Shouldn't it be `com.mysql` instead of `com.sql` in the class name? – Thilo Nov 30 '16 at 09:48
  • 2
    Can you give more information? SE project? Web Project? Maven? – JonahCui Nov 30 '16 at 09:49
  • 2
    You need to make sure the JDBC driver for MySQL is on the classpath when you run your application, and spell the name of the driver class correctly. Upper- and lower-case characters are important. The driver class is not named `com.sql.jdbc.driver`. That your processor is 64-bit has nothing to do with this error. – Jesper Nov 30 '16 at 09:49
  • Always include your code. It helps people to give you a more precise and quicker feedback. – Tom Nov 30 '16 at 09:51
  • Thanks I'm running it on the command prompt. – Victor Nov 30 '16 at 10:04
  • 1
    Possible duplicate of [Connect Java to a MySQL database](http://stackoverflow.com/questions/2839321/connect-java-to-a-mysql-database) – andolsi zied Nov 30 '16 at 10:58

0 Answers0