java.lang.Classnotfound异常:com.sql.jdbc.driver错误

时间:2016-11-30 09:47:33

标签: java mysql jdbc

我正在尝试使用MySQL Java Connector 5.1.8将我的Java程序连接到数据库,但我一直有java.lang.Classnotfound exception: com.sql.jdbc.driver错误。

有人可以帮我解决这个问题吗?顺便说一句:我有64位处理器。

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) {
    }

0 个答案:

没有答案