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.
本人用得是校园网 没有什么关系的吧 什么防火墙软件都关闭了
------解决方案--------------------------------------------------------
- Java code
String url=("jdbc:mysql://localhost:3306/gh");//是localhost,不是localhosst
------解决方案--------------------------------------------------------
------解决方案--------------------------------------------------------
------解决方案--------------------------------------------------------
对了如果楼主学校用的是Dr.com的话 那以后编程中会遇到很多问题的?如果有些问题实在解决不了那就关了Dr.com 然后修复LSP即可