代码如下:
import java.sql.*;public class ExecSQL
{
public static void main(String args[ ])
{
String driver ="com.mysql.jdbc.Driver";
String url ="jdbc:mysql://localhost:3306//corejava";
String user ="root";
String password= "123";
try
{
Class.forName(driver);Connection con=DriverManager.getConnection(url,user,password);
if(!con.isClosed())
System.out.println("打开数据库成功");
con.close();
}
catch (ClassNotFoundException e) {
System.out.print("无法加载驱动:"+driver);
e.printStackTrace();
}
catch(SQLException SE)
{
System.out.print("打开数据库失败");

}
}
网上看了很多文章,该配的classpath我都配了,可还是提示"打开数据库失败",我有一个疑问,我用的是官方的那个driver,下载下来是zip格式,但我看网上都说是jar格式,我解压开以后始终不知道该用哪个jar,有知道的麻烦告诉下,万分感谢..