📄 databaseservice.java
字号:
/**
*
*/
package flow.graph.db.bean;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import flow.graph.db.SQLiteConnection;
import flow.graph.util.Encoder;
/**
* @author Administrator
*
*/
public class DataBaseService {
public static List selectService(Connection con) throws SQLException {
//log.info("CardUserRequest.checkUser;phone="+phone);
PreparedStatement stmt = null;
ResultSet rest = null;
List list = new ArrayList();
String sql = "select * from service order by t_id asc";
try{
stmt = con.prepareStatement(sql);
rest = stmt.executeQuery();
while(rest.next()){
ServiceBean service = new ServiceBean();
service.setT_id(rest.getInt("t_id"));
service.setT_name(rest.getString("t_name"));
list.add(service);
}
return list;
} catch (SQLException e){
throw e;
}
finally{
try {
if(rest != null)
rest.close();
if(stmt != null)
stmt.close();
if(con != null)
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
throw e;
}
}
}
public static ServiceBean selectServiceIdByName(Connection con, String s) {
PreparedStatement stmt = null;
ResultSet rest = null;
String sql = "select * from service where t_name = ? order by t_id desc limit 0, 1";
try{
stmt = con.prepareStatement(sql);
stmt.setString(1, s);
rest = stmt.executeQuery();
if(rest.next()){
ServiceBean service = new ServiceBean();
service.setT_id(rest.getInt("t_id"));
service.setT_name(rest.getString("t_name"));
return service;
}
return null;
} catch (SQLException e){
System.out.println(e.getMessage());
return null;
}
finally{
try {
if(rest != null)
rest.close();
if(stmt != null)
stmt.close();
if(con != null)
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public static ServiceBean insertService(Connection con, String name) throws SQLException {
PreparedStatement stmt = null;
ResultSet rest = null;
String sql = "insert into service(t_name) values(?)";
try{
stmt = con.prepareStatement(sql);
stmt.setString(1, name);
if(stmt.executeUpdate() > 0){
sql = "select * from service order by t_id desc limit 0, 1";
stmt = con.prepareStatement(sql);
rest = stmt.executeQuery();
if(rest.next()){
ServiceBean bean = new ServiceBean();
bean.setT_id(rest.getInt("t_id"));
bean.setT_name(rest.getString("t_name"));
bean.setT_enterid(rest.getInt("t_enterid"));
return bean;
}
else{
throw new SQLException("DataBaseService:insertService-->get t_id failed!");
}
}
else
throw new SQLException("DataBaseService:insertService execute failed!");
} catch (SQLException e){
throw e;
}
finally{
try {
if(rest != null)
rest.close();
if(stmt != null)
stmt.close();
if(con != null)
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
throw e;
}
}
}
public static int updateServiceEnterID(Connection con, ServiceBean bean) {
PreparedStatement stmt = null;
ResultSet rest = null;
String sql = "update service set t_enterid = ? where t_id = ?";
try{
stmt = con.prepareStatement(sql);
stmt.setInt(1, bean.getT_enterid());
stmt.setInt(2, bean.getT_id());
return stmt.executeUpdate();
} catch (SQLException e){
System.out.println(e.getMessage());
}
finally{
try {
if(rest != null)
rest.close();
if(stmt != null)
stmt.close();
if(con != null)
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return 0;
}
public static int updateService(Connection con, ServiceBean bean) throws SQLException {
PreparedStatement stmt = null;
ResultSet rest = null;
String sql = "update service set t_name = ? where t_id = ?";
try{
stmt = con.prepareStatement(sql);
stmt.setString(1, bean.getT_name());
stmt.setInt(2, bean.getT_id());
return stmt.executeUpdate();
} catch (SQLException e){
throw e;
}
finally{
try {
if(rest != null)
rest.close();
if(stmt != null)
stmt.close();
if(con != null)
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
throw e;
}
}
}
public static int deleteService(Connection con, int id) throws SQLException {
//删除业务节点,同时删除该业务下的所有节点
PreparedStatement stmt = null;
ResultSet rest = null;
String sql = "delete from service where t_id = ?";
try{
stmt = con.prepareStatement(sql);
stmt.setInt(1, id);
return stmt.executeUpdate();
} catch (SQLException e){
throw e;
}
finally{
try {
if(rest != null)
rest.close();
if(stmt != null)
stmt.close();
if(con != null)
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
throw e;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -