JDBCUtils-获取连接与关闭

public class JDBCUtils {
 public static Connection getConnection() throws Exception{
  InputStream is = new FileInputStream(new File("jdbc.properties"));
  Properties p = new Properties();
  p.load(is);
  String driverName =  p.getProperty("driverName");
  String url = p.getProperty("url");
  String user = p.getProperty("user");
  String password = p.getProperty("password");
  Class.forName(driverName);
  Connection connection = DriverManager.getConnection(url, user, password);
  return connection;  
 }
 public static void close(ResultSet rs, Statement s , Connection connection){
  try {
   if(rs!=null){
    rs.close();
   }
  } catch (Exception e) {
   e.printStackTrace();
  }
  try {
   if(s!=null){
    s.close();
   }
  } catch (Exception e) {
   e.printStackTrace();
  }
  try {
   if(connection!=null){
    connection.close();
   }
  } catch (Exception e) {
   e.printStackTrace();
  }
 }
}

你可能感兴趣的:(JDBCUtils-获取连接与关闭)