请问如何在Java中访问Mysql数据库_____一段小程序
import java.sql.*;
public class ConnectMySql {
public static void main(String args[]) {
String driver = "org.gjt.mm.mysql.Driver";
String url = "jdbc:mysql://localhost:3306/huotw";
String user = "huotw";
String password = "810120";
try {
Class.forName(driver).newInstance();
}
catch(Exception e) {
System.out.println("无法加载驱动程序:" + driver);
}
try {
Connection con = DriverManager.getConnection(url,user,password);
if(!con.isClosed())
System.out.println("数据库连接成功!");
con.close();
}
catch(SQLException ee) {
System.out.println("数据库连接失败!");
}
}
}
为什么总是连接失败呀?请各位帮忙分析一下!