日期:2014-05-20  浏览次数:20644 次

请教jdbc无法访问mysql
使用的是mysql 5.0 驱动包下的也是5.0的 默认端口也没有改过,但是却报错说是 No suitable driver found for jdbc:mysql://127.0.0.1:3306
static{
String driverName = "com.mysql.jdbc.Driver";
try{
Class.forName(driverName);
}catch(Exception e){
e.printStackTrace();
}
}


//建立向MYSQL的连接
public static Connection getConnectionToMysql(){
String url = "jdbc:mysql://127.0.0.1:3306";
String userName = "123456";
String pwd ="123456";
Connection con = null ;
try{
con =DriverManager.getConnection(url,userName,pwd);
return con ;
}catch(Exception e){
e.printStackTrace();
}
return null;

}

------解决方案--------------------
驱动包导入到项目下没有呢?
------解决方案--------------------
url写错了,没有跟数据库名
jdbc:mysql://localhost:3306/dbname
------解决方案--------------------
2楼正解