java数据库工具类
本工具类主要运用到了集合的知识
DbHelper.java
public class DbHelper {
private Connection connection;
private PreparedStatement preparedStatement;
private ResultSet resultSet;
public DbHelper()
{
getConnection();
}
//打开连接
public void getConnection()
{
try {
if(connection==null || connection.isClosed())
{
//将文件中的数据转到集合中 再从集合取数据
Properties properties=new Properties();
InputStream iStream=this.getClass().getResourceAsStream("/db.properties");
properties.load(iStream);
//获得集合中数据
String driver=properties.getProperty("driver");
String url=properties.getProperty("url");
String uname=properties.getProperty("uname");
String pwd=properties.getProperty("pwd");
Class.forName(driver);
this.connection= DriverManager.getConnection(url