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); }}
添加回答
举报
0/150
提交
取消