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-获取连接与关闭
最新推荐文章于 2023-06-09 17:38:28 发布