大神,帮我看看,为什么我可以加载驱动,却一直连接不上!!包也导入了,到底是什么问题


package Affairs;

import java.sql.*;

public class StudentsDbDrivers {
 public static Connection getConnection() {
  Connection conn = null;
  try {
   
   Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
   
   conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/Education affair","sa","");
   if (conn != null) {
    System.out.println("连接成功");
   }
  } catch (ClassNotFoundException e) {
   System.out.println("驱动器加载失败!!");
  } catch (SQLException e) {
   System.out.println("驱动连接失败");
  }
  return conn;
 }

 public static void closeConnection(Connection conn) {
  if (conn != null) {
   try {
    conn.close();
    System.out.println("关闭连接成功");
   } catch (SQLException e) {
    System.out.println("关闭失败");
   }
  }
 }

 public static void main(String[] args) {
  Connection conn = getConnection();
  closeConnection(conn);

 }

}

Calvin1
浏览 1224回答 0
0回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java