public class JDBCUtils {
static String driverClass = null;
static String url = null;
static String user = null;
static String password = null;
static {
Properties prop = new Properties();
try {
FileInputStream in = new FileInputStream("jdbc.properties");
prop.load(in);
driverClass = prop.getProperty("driverClass");
url = prop.getProperty("url");
user = prop.getProperty("user");
password = prop.getProperty("password");
Class.forName(driverClass);
} catch (Exception e) {
e.printStackTrace();
}
}
public static Connection getConnection() {
Connection con = null;
try {
con = DriverManager.getConnection(url, user, password);
return con;
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
public static void release(Connection conn, Statement stmt, ResultSet rs) {
try {
if (rs != null) {
rs.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
try {
if (stmt != null) {
stmt.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
try {
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}