刚学数据库 出现的问题 快进来看看大师们

dazhanhongtao 2012-06-11 09:34:51
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.
本人用得是校园网 没有什么关系的吧 什么防火墙软件都关闭了
...全文
132 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
ncisjava 2012-06-12
  • 打赏
  • 举报
回复
检查服务是否开启,服务没开会显示上面的错误信息
dazhanhongtao 2012-06-11
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

引用 1 楼 的回复:

Java code

String url=("jdbc:mysql://localhost:3306/gh");//是localhost,不是localhosst

+1
[/Quote]还是一样啊 怎么样的吗
Luger 2012-06-11
  • 打赏
  • 举报
回复
对了如果楼主学校用的是Dr.com的话 那以后编程中会遇到很多问题的?如果有些问题实在解决不了那就关了Dr.com 然后修复LSP即可
Luger 2012-06-11
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

Java code

String url=("jdbc:mysql://localhost:3306/gh");//是localhost,不是localhosst
[/Quote]
+1
fuhonghao 2012-06-11
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
Java code


String url=("jdbc:mysql://localhost:3306/gh");//是localhost,不是localhosst
[/Quote]
楼上正解!
脉动 2012-06-11
  • 打赏
  • 举报
回复

String url=("jdbc:mysql://localhost:3306/gh");//是localhost,不是localhosst

62,628

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧