/**
* 创建conn连接
* @return
*/
public boolean CONN(){
try{
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection(url,mysqluser,mysqlpass);
statement=conn.createStatement();
return true;
}catch(Exception e)
{
System.out.println(e);
return false;
}
}
/**
* 关闭数据库
*/
public void closedb(){
try {
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* 查询语句
* @param sql
* @return
*/
public ResultSet Select(String sql){
//if(this.CONN()){
try{
rs=statement.executeQuery(sql);
}
catch(Exception e){}
return rs;
//}
//else
//return null;
}
/**
* 执行SQL语句
* @param sql
* @return
*/
public boolean ExcuteSql(String sql){
boolean x=false;
//if(this.CONN())
//{
try{
statement.executeUpdate(sql);
x=true;
}
catch(Exception e){e.printStackTrace();
}
//}
return x;
}
/**
* 执行数据库事务
* @param al
* @return
*/
public boolean ExcuteTrans(ArrayList al){
boolean x=false;
//if(this.CONN()){
try{
conn.setAutoCommit(false);
for(int i=0;i<al.size();i++){
String y=al.get(i).toString();
statement.execute(y);
}
conn.commit();
conn.setAutoCommit(true);
x=true;
}catch(Exception e){
try{
conn.rollback();
conn.setAutoCommit(true);
}
catch(Exception ex){}
}
return x;
//}
//return x;
}