public class DB_Method extends DB_Util{
private Connection con =null;
private PreparedStatement pstmt = null;
private ResultSet rs= null;
public int regist(String sql,Object []object){
con = getConnection();
int userId=0;
try {
pstmt = con.prepareStatement(sql,Statement.RETURN_GENERATED_KEYS);
if(object!=null){
for(int i = 0 ; i<object.length;i++){
pstmt.setObject(i+1, object[i]);
}
}
int row = pstmt.executeUpdate();
if(row>0){
rs = pstmt.getGeneratedKeys();
if(rs.next()){
userId=rs.getInt(1);
}
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
close(con, pstmt, rs);
}
return userId;
}
public boolean update(String sql,Object []object){
boolean b = false;
con = getConnection();
try {
pstmt = con.prepareStatement(sql);
if(object!=null){
for(int i = 0;i<object.length;i++){
pstmt.setObject(i+1, object[i]);
}
}
int row = pstmt.executeUpdate();
if(row>0){
b=true;
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
close(con, pstmt, null);
}
return b;
}
public ResultSet query(String sql,Object []object){
con = getConnection();
try {
pstmt = con.prepareStatement(sql);
if(object!=null){
for(int i =0;i<object.length;i++){
pstmt.setObject(i+1, object[i]);
}
}
rs = pstmt.executeQuery();
} catch (SQLException e) {
e.printStackTrace();
}
return rs;
}
public void close(ResultSet rs){
close(con,pstmt,rs);
}
}
private Connection con =null;
private PreparedStatement pstmt = null;
private ResultSet rs= null;
public int regist(String sql,Object []object){
con = getConnection();
int userId=0;
try {
pstmt = con.prepareStatement(sql,Statement.RETURN_GENERATED_KEYS);
if(object!=null){
for(int i = 0 ; i<object.length;i++){
pstmt.setObject(i+1, object[i]);
}
}
int row = pstmt.executeUpdate();
if(row>0){
rs = pstmt.getGeneratedKeys();
if(rs.next()){
userId=rs.getInt(1);
}
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
close(con, pstmt, rs);
}
return userId;
}
public boolean update(String sql,Object []object){
boolean b = false;
con = getConnection();
try {
pstmt = con.prepareStatement(sql);
if(object!=null){
for(int i = 0;i<object.length;i++){
pstmt.setObject(i+1, object[i]);
}
}
int row = pstmt.executeUpdate();
if(row>0){
b=true;
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
close(con, pstmt, null);
}
return b;
}
public ResultSet query(String sql,Object []object){
con = getConnection();
try {
pstmt = con.prepareStatement(sql);
if(object!=null){
for(int i =0;i<object.length;i++){
pstmt.setObject(i+1, object[i]);
}
}
rs = pstmt.executeQuery();
} catch (SQLException e) {
e.printStackTrace();
}
return rs;
}
public void close(ResultSet rs){
close(con,pstmt,rs);
}
}