刚学数据库 出现的问题 快进来看看大师们
import java.sql.*;
public class GetConn {
public Connection conn=null;
public void getconnection(){
try{
//Class.forName("org.gjt.mm.mysql.Driver");
String url=("jdbc:mysql://localhosst:3306/gh");
String user="root";
String password="123456";
conn=DriverManager.getConnection(url,user,password);
if(conn!=null){
System.out.println("数据库连接成功");
}
}
catch(Exception e){
System.out.println(e.getMessage());
}
return ;
}
public static void main(String args[]){
GetConn ob=new GetConn();
ob.getconnection();
}
}
连接时候出现的提示:
Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
本人用得是校园网 没有什么关系的吧 什么防火墙软件都关闭了
[解决办法]
String url=("jdbc:mysql://localhost:3306/gh");//是localhost,不是localhosst
[解决办法]