为了账号安全,请及时绑定邮箱和手机立即绑定

测试连接MySQL数据库时,加载驱动加载的了,连接数据库连接不上,哪位能帮我一下

测试连接MySQL数据库时,加载驱动加载的了,连接数据库连接不上,哪位能帮我一下

慕神4704991 2018-08-01 22:59:28
附上代码,我自己在数据库中建的conn数据库密码时mysqlpublic class DBTest { @Test public void test()  {  final String url="jdbc:mysql://localhost:3306/conn";  final String user="root";  final String password="mysql";  try {  Class.forName("com.mysql.jdbc.Driver");  Connection conn = DriverManager.getConnection(url, user, password);   System.out.println(conn);  }  catch(ClassNotFoundException e) {   e.printStackTrace();   System.out.println("未找到驱动程序");  } catch (SQLException e) {   // TODO Auto-generated catch block   e.printStackTrace();   System.out.println("数据库连接出现异常");  }   }}
查看完整描述

2 回答

已采纳
?
qq_a沙漏中的时光_0

TA贡献13条经验 获得超2个赞

  1. 使用SQLyog看是否能连上你的数据库

  2. 查看mysql的服务是否启动

    https://img1.sycdn.imooc.com//5b88237a0001fc9512630597.jpg

查看完整回答
反对 回复 2018-08-31
?
望远

TA贡献1017条经验 获得超1032个赞

  1. 确保mysql-jdbc驱动加载到了项目引用jar中

    https://img1.sycdn.imooc.com//5b66d6a60001823403040045.jpg

  2. 检查mysql数据库端口是否为3306,show global variables like 'port';

    https://img1.sycdn.imooc.com//5b66d71e0001d87903970120.jpg

  3. 确保数据库用户名和密码正确

  4. 确保数据库conn存在,show databases;

查看完整回答
反对 回复 2018-08-05
  • 慕神4704991
    慕神4704991
    已经解决了,原因是我导入的jdbc版本太新,在url后面加上?serverTimezone=GMT
  • 2 回答
  • 0 关注
  • 1486 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信