标签:cat resultset 关闭 .sql ret tco 数据库连接 tst generated
package Util; import java.sql.*; public class DBUtil { public static Connection getConnection() { Connection conn = null; try { Class.forName("oracle.jdbc.driver.OracleDriver"); //加载数据库驱动 System.out.println("数据库驱动加载成功!"); //输出的信息 String url = "jdbc:oracle:thin:@localhost:1521:orcl"; //获取连接URL String user = "TEACHER"; //连接用户名 String password = "***"; //连接密码 Connection con = DriverManager.getConnection(url, user, password); //获取数据库连接 if (con != null) { System.out.println("成功的与Oracle数据库建立连接!!"); } } catch (Exception e) { e.printStackTrace(); } return conn; //返回Connection实例 } //关闭资源的方法 public static void close(Connection connection ) { try { if (connection != null) { connection.close(); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void close(PreparedStatement preparedStatement ) { try { if (preparedStatement != null) { preparedStatement.close(); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void close(ResultSet resultSet ) { try { if (resultSet != null) { resultSet.close(); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
标签:cat resultset 关闭 .sql ret tco 数据库连接 tst generated
原文地址:https://www.cnblogs.com/lijing925/p/9606098.html