public class JdbcUtil {
private static String driver=null;//驱动
private static String url=null;//连接地址
private static String username=null;//用户名
private static String password=null;//密码
static {
try {
Properties props=new Properties();
InputStream ins = JdbcUtil.class.getClassLoader().getResourceAsStream("jdbc.properties");
props.load(ins);
driver = props.getProperty("driver");
url = props.getProperty("url");
username = props.getProperty("username");
password = props.getProperty("password");
Class.forName(driver);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Description:获取数据连接<br/>
* @return yuanQiSheng
* @throws Exception
*/
public static Connection getConnection() throws Exception {
return DriverManager.getConnection("url","username","password");
}
/**
* Description:释放数据库资源<br/>
* @param conn:Connection
* @param pres:PreparedStatement
* @param rs:ResultSet
*/
public static void release(Connection conn,PreparedStatement pres,ResultSet rs) {
try {
if(rs!=null) {
rs.close();
}
} catch (Exception e) {
e.printStackTrace();
}
try {
if(pres!=null) {
pres.close();
}
} catch (Exception e) {
e.printStackTrace();
}
try {
if(conn!=null) {
conn.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
05-11 22:07