import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class BaseDao {
public static final String DB_DRIVER="com.mysql.jdbc.Driver";
public static final String DB_URL="jdbc:mysql:///test";
public static final String DB_USER="root";
public static final String DB_PWD="1234";
protected Connection conn=null;
protected PreparedStatement pstmt=null;
protected ResultSet rs=null;
protected Connection getConn(){
try{
Class.forName("DB_DRIVER");
conn=DriverManager.getConnection(DB_URL,DB_USER,DB_PWD);
}catch(SQLException e){
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return conn;
}
protected void releaseAll(Connection conn,PreparedStatement pstmt,ResultSet rs){
if(conn!=null){
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(pstmt!=null){
try {
pstmt.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(rs!=null){
try {
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
} |
|