sqlserverchargedao.java
来自「中国移动管理系统」· Java 代码 · 共 93 行
JAVA
93 行
package com.chinamobile.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Iterator;
import com.chinamobile.bean.ChargeBean;
import com.chinamobile.bean.MobileBean;
import com.chinamobile.bean.OperatorBean;
public class SQLServerChargeDAO implements ChargeDAO {
private final String INSERT_AN_CHARGE = "insert into TCharge values(?,?,?)";
private final String GET_AN_CHARGE = "select * from TCharge where Charge_Code=?";
public boolean createCharge(ChargeBean charge) {
Connection conn =null;
PreparedStatement pstmt=null;
boolean tmp=true;
try{
conn=SQLServerDAOFactory.getConnection();
pstmt=conn.prepareStatement(INSERT_AN_CHARGE);
pstmt.setString(1, charge.getCharge_Code());
pstmt.setString(2, charge.getCharge_Name());
pstmt.setString(3, charge.getCharge());
int result=pstmt.executeUpdate();
if(result!=1)
tmp = false;
}catch(SQLException e){
tmp = false;
e.printStackTrace();
}finally{
SQLServerDAOFactory.closeStatement(pstmt);
SQLServerDAOFactory.closeConnection(conn);
}
return tmp;
}
public boolean isExists(ChargeBean charge) {
Connection conn =null;
PreparedStatement pstmt=null;
boolean tmp=true;
try{
conn=SQLServerDAOFactory.getConnection();
pstmt=conn.prepareStatement(GET_AN_CHARGE);
pstmt.setString(1, charge.getCharge_Code());
ResultSet result=pstmt.executeQuery();
if(result.next()){
tmp = true;
}else{
tmp = false;
}
}catch(SQLException e){
e.printStackTrace();
}finally{
SQLServerDAOFactory.closeStatement(pstmt);
SQLServerDAOFactory.closeConnection(conn);
}
return tmp;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?