请教jdbc连接mysql的问题。

funking 2004-08-12 03:02:41
try {
String url="jdbc:mysql://localhost:3306/sysMng";
String user="root";
String passwd="";
try {
Class.forName("org.gjt.mm.mysql.Driver");
System.out.println("Opening db connection");
System.out.println(conn);

conn = DriverManager.getConnection(url, user, passwd);
}
catch (ClassNotFoundException ex) {
System.err.println("Cannot find the database driver classes.");
System.err.println(ex);
}
catch (SQLException ex) {
System.err.println("Cannot connect to this database.");
System.err.println(ex);
}
}
catch(Exception e) {
e.printStackTrace();
}

报错信息如下:
java.sql.SQLException: Cannot connect to MySQL server on localhost:3306. Is there a MySQL server running on the machine/port you are trying to connect to? (java.lang.NumberFormatException)
...全文
136 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
nwsl 2004-08-12
  • 打赏
  • 举报
回复
或者打开了,可是mysql的端口不是3306。
nwsl 2004-08-12
  • 打赏
  • 举报
回复
你没启动mysql服务器。
newsunet 2004-08-12
  • 打赏
  • 举报
回复
设置mysql 的驱动的包的路径
set classpath=n:\....\.....\*??.jar
把路径和文件名换成你的地址
bozy 2004-08-12
  • 打赏
  • 举报
回复
1.你的mysql服务是否启动,用户名密码是否正确
2。你的classes是否存在(org.gjt.mm.mysql.Driver)包
yyqllxh2004 2004-08-12
  • 打赏
  • 举报
回复
看看运行没,再有可以这样写,可以解决中文问题:)

Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url="jdbc:mysql://192.168.1.61/AddrBook_databaseuser=heyi&password=123&useUnicode=true&characterEncoding=GB2312";
Connection conn= DriverManager.getConnection(url);

xuyang821225 2004-08-12
  • 打赏
  • 举报
回复
恩,服务器都没开
liujiansxcd 2004-08-12
  • 打赏
  • 举报
回复
mysql没有运行吧?

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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