📄 db.java
字号:
/*
* DB.java
*
* Created on 2008年1月11日, 上午9:33
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package com.myapp.struts;
/**
*
* @author Administrator
*/
import java.sql.*;
import java.util.ArrayList;
public class DB {
private static String url="jdbc:mysql://localhost:3306/paysystem?user=root&password=root";
Connection conn=null;
Statement statement=null;
ResultSet rs=null;
//这里数据库连接必需放在方法里,要不然会报错。
public boolean CONN(){
try{
Class.forName("com.mysql.jdbc.Driver");//.newInstance();
conn= DriverManager.getConnection(url);
statement = conn.createStatement();
return true;
}catch(Exception e){return false;}
}
public ResultSet Select(String sql){
if(this.CONN())
{
try{
rs = statement.executeQuery(sql);
}
catch(Exception e){}
return rs;
}
else return null;
}
public boolean ExcuteSql(String sql){
boolean x=false;
if(this.CONN())
{
try{
statement.executeUpdate(sql);
x=true;
}catch(Exception e){e.printStackTrace();}
}
return x;
}
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;
}
public void DBClose(){
try{
if(statement!=null){statement.close();}
if(conn!=null){conn.close();}
}catch(Exception e){}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -