线程“main”java.sql.SQLException中的异常:找不到合适的驱动程序

时间:2014-12-16 13:52:46

标签: java mysql eclipse jdbc

我试图连接MySQL数据库,我在localhost上用phpmyadmin创建了SQL数据库。我的代码似乎是正确的,我将JAR文件添加到eclipse中。我搜索了这个错误,并在这里找到了许多相同的主题,但是我们无法解决问题。这是我的代码:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;


public class dbconnection {
    public static void main (String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.jdbc.Driver");
        Connection con = DriverManager.getConnection("jdbc:msql://localhost:3306/g52apr","root", "");
        java.sql.PreparedStatement statement = con.prepareStatement("select * from std_details");
        ResultSet result = statement.executeQuery();
        while (result.next()){
            System.out.println(result.getString(1) + " " + result.getString(2));
        }
    }
}

这是确切的错误:

Exception in thread "main" java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver://localhost:3306/g52apr
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at dbconnection.main(dbconnection.java:10)

1 个答案:

答案 0 :(得分:0)

"jdbc:msql://localhost:3306/g52apr"

应该是:

"jdbc:mysql://localhost:3306/g52apr"

已编辑已将SQL Server引用更改为MySql