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

新手问一个连MYSQL的问题
以前一直是用MSSQL的驱动连,加三个JAR文件
public   DBFactory()里写{
this.dbclass= "com.microsoft.jdbc.sqlserver.SQLServerDriver ";
this.dbuid= "sa ";
this.dbpwd= " ";
      this.dburl= "jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=... ";
那连MYSQL的话,dbclass和dburl应该怎么改,还有是不是MYSQL只有mysql-connector-java-5.0.3-bin.jar这一个外部JAR,谢谢~~

------解决方案--------------------
public static Connection getConnection(){
Connection conn = null;
String CLASSFORNAME = "org.gjt.mm.mysql.Driver ";
String USERNAME = " ";
String PWD = " ";
String SERVANDDB = "jdbc:mysql://localhost/数据库 user= "+USERNAME+ "&password= "+PWD;
try{
Class.forName(CLASSFORNAME);
conn = DriverManager.getConnection(SERVANDDB);
}catch(Exception e){
e.printStackTrace();
}
return conn;
}