package com.car.dao;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;
import com.car.pojo.Car;
public class BaseDao {
private static String driver = null;
private static String url = null;
private static String userName = null;
private static String password = null;
private static final String resource = "database.properties";
protected Connection conn = null;
protected PreparedStatement ps = null;
ResultSet rs = null;
public void setRs(ResultSet rs) {
this.rs = rs;
}
static{
InputStream in = BaseDao.class.getClassLoader().getResourceAsStream(resource);
Properties properties = new Properties();
try {
properties.load(in);
driver = properties.getProperty("jdbc.driver");
url = properties.getProperty("jdbc.url");
userName = properties.getProperty("jdbc.userName");
password = properties.getProperty("jdbc.password");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static Connection getConnection() throws Exception{
//1.加载驱动
Class.forName(driver);
//2.获取连接
Connection connection = DriverManager.getConnection(url, userName, password);
return connection;
}
public static void release(Connection conn,PreparedStatement ps,ResultSet rs) throws Exception{
if(conn!=nu