javaDBhelp

package DBhelp;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

public class jdbcUtils {
private static String driver = null;
private static String url = null;
private static String user = null;
private static String password = null;

static{
try {
InputStream in= jdbcUtils.class.getClassLoader().getResourceAsStream("db.propertres");
Properties properties = new Properties();
properties.load(in);
driver = properties.getProperty("driver");
url = properties.getProperty("url");
user = properties.getProperty("user");
password = properties.getProperty("password");

//加载驱动一次
Class.forName(driver);
} catch (Exception e) {
// TODO: handle exception
}
}
//获取连接
public static Connection getConnection() throws SQLException{

return DriverManager.getConnection(url, user, password);
}
//释放资源
public static void relase(Connection conn,Statement stmt,ResultSet rs){
try {
if (null!=conn) conn.close();
if (null!=stmt) stmt.close();
if (null!=rs) rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
}

javaDBhelp

 

javaDBhelp

上一篇:数据库练习题


下一篇:[ZZ]c++ cout 格式化输出浮点数、整数及格式化方法