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

附上代码,我自己在数据库中建的conn数据库密码时mysql

public 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("数据库连接出现异常");
  }
  
 }
}

慕神4704991
浏览 1493回答 2
2回答

qq_a沙漏中的时光_0

使用SQLyog看是否能连上你的数据库查看mysql的服务是否启动

望远

确保mysql-jdbc驱动加载到了项目引用jar中检查mysql数据库端口是否为3306,show global variables like 'port';确保数据库用户名和密码正确确保数据库conn存在,show databases;
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java
MySQL