📄 spbusinessdao.java
字号:
package com.gctech.sms.dao;
import com.gctech.sms.vo.SpBusinessObject;
import java.sql.Connection;
import java.sql.PreparedStatement;
import com.gctech.sms.util.ConnectionManager;
import org.apache.log4j.Logger;
import java.util.Collection;
import java.util.Vector;
import java.sql.Statement;
import java.sql.ResultSet;
import com.gctech.sms.vo.SmsServiceObject;
import java.util.HashMap;
import java.util.Map;
import java.sql.*;
import java.util.ArrayList;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: gctech</p>
* @author 王红宝
* @version $Id: SpBusinessDao.java,v 1.2 2004/04/22 01:25:16 wanghb Exp $
*/
public class SpBusinessDao {
public SpBusinessDao() {
}
/**
* 找到所有的SpBusiness对象,和与之对应的SmsService。
* */
public static Map findAll(){
Map rt = new HashMap();
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try{
con = ConnectionManager.getInstance().getConnection(SpBusinessDao.class);
stmt = con.createStatement();
rs = stmt.executeQuery("select sb.id,sb.BUSINESSNAME,sb.SERVICEID,ss.feetype,ss.feecode,ss.subtype,ss.msgformat from"+
" spbusiness sb, smsservice ss where sb.serviceid=ss.id");
while ( rs.next() ){
SpBusinessObject sb = new SpBusinessObject();
sb.setID(rs.getString(1));
sb.setBusinessName(rs.getString(2));
SmsServiceObject svc = new SmsServiceObject();
svc.setID(rs.getString(3));
svc.setFeeType(rs.getString(4));
svc.setFeeCode(rs.getString(5));
svc.setSubType(rs.getInt(6));
svc.setMsgFormat(rs.getByte(7));
sb.setService(svc);
rt.put(sb.getID(), sb);
}
}catch( Throwable e ){
logger.error(e, e);
}finally{
if ( rs != null ){
try {
rs.close();
}
catch (Throwable ex) {
logger.error(ex, ex);
}
}
if ( stmt != null ){
try {
stmt.close();
}
catch (Throwable ex) {
logger.error(ex, ex);
}
}
if ( con != null ){
try {
con.close();
}
catch (Throwable ex) {
logger.error(ex, ex);
}
}
}
return rt;
}
public static int add(SpBusinessObject obj){
int rt = -1;
Connection con = null;
PreparedStatement pstmt = null;
try{
con = ConnectionManager.getInstance().getConnection(MOCommandDao.class);
pstmt = con.prepareStatement(
"insert into spbusiness(ID,BUSINESSNAME,SERVICEID)values(?,?,?)");
pstmt.setString(1, obj.getID());
pstmt.setString(2, obj.getBusinessName());
pstmt.setString(3, obj.getServiceId());
pstmt.execute();
rt = 0;
}catch( Throwable e ){
logger.error(e, e);
}finally{
if ( pstmt != null ){
try {
pstmt.close();
}
catch (Throwable ex) {
logger.error(ex, ex);
}
}
if ( con != null ){
try {
con.close();
}
catch (Throwable ex) {
logger.error(ex, ex);
}
}
return rt;
}
}
public SpBusinessObject[] getAllSp(SpBusinessObject infovalue) throws SQLException {//查询所有数据
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
ArrayList list = new ArrayList();
try{
con = ConnectionManager.getInstance().getConnection(SpBusinessDao.class);
StringBuffer sql = new StringBuffer("select a.id,a.businessname,a.serviceid,");
sql.append( "a.isprepay");
sql.append( " from spbusiness a");
sql.append(" where 1=1");
if (infovalue!=null && infovalue.getID()!=null && !infovalue.getID().equals("")){
sql.append(" and a.id = '" + infovalue.getID() + "'");
}
if (infovalue!=null && infovalue.getServiceId()!=null && !infovalue.getServiceId().equals("")){
sql.append(" and a.serviceid = '" + infovalue.getServiceId() + "'");
}
logger.debug(sql.toString());
pstmt = con.prepareStatement(sql.toString());
rs = pstmt.executeQuery();
while (rs.next()){
SpBusinessObject model = new SpBusinessObject();
String id = rs.getString("id");
if (!rs.wasNull()) model.setID(id);
String businessname = rs.getString("businessname");
if (!rs.wasNull()) model.setBusinessName(businessname);
String serviceid = rs.getString("serviceid");
if (!rs.wasNull()) model.setServiceId(serviceid);
int isprepay = rs.getInt("isprepay");
if (!rs.wasNull()) model.setIsprepay(isprepay);
list.add(model);
}
}catch( Throwable e ){
logger.error(e, e);
}finally{
if ( rs != null ){
try {
rs.close();
}
catch (Throwable ex) {
logger.error(ex, ex);
}
}
if ( pstmt != null ){
try {
pstmt.close();
}
catch (Throwable ex) {
logger.error(ex, ex);
}
}
if ( con != null ){
try {
con.close();
}
catch (Throwable ex) {
logger.error(ex, ex);
}
}
}
//返回数据
logger.debug("12313123");
return (SpBusinessObject[])list.toArray(new SpBusinessObject[list.size()]);
}
public int deleteSp(SpBusinessObject infovalue) throws SQLException {//删除数据
Connection con = null;
PreparedStatement pstmt = null;
int rs = 0 ;
try{
con = ConnectionManager.getInstance().getConnection(SpBusinessDao.class);
StringBuffer sql = new StringBuffer("delete from spbusiness where 1=1 ");
sql.append( "and spbusiness.id = '" + infovalue.getID() + "'");
pstmt = con.prepareStatement(sql.toString());
rs = pstmt.executeUpdate();
}catch( Throwable e ){
logger.error(e, e);
}finally{
if ( pstmt != null ){
try {
pstmt.close();
}
catch (Throwable ex) {
logger.error(ex, ex);
}
}
if ( con != null ){
try {
con.close();
}
catch (Throwable ex) {
logger.error(ex, ex);
}
}
}
//返回数据
return rs;
}
public int updateSp(SpBusinessObject infovalue) throws SQLException {//更新数据
Connection con = null;
PreparedStatement pstmt = null;
int rs = 0 ;
try{
con = ConnectionManager.getInstance().getConnection(SpBusinessDao.class);
StringBuffer sql = new StringBuffer("update spbusiness set ");
sql.append( " spbusiness.businessname = '" + infovalue.getBusinessName() + "',");
sql.append( " spbusiness.serviceid = '" + infovalue.getServiceId() + "',");
sql.append( " spbusiness.isprepay = '" + infovalue.getIsprepay() + "',");
sql.setLength(sql.length()-1);
sql.append( " where 1=1");
if (infovalue.getID()!=null){
sql.append(" and spbusiness.id = '" + infovalue.getID() + "'");
}
logger.debug(sql.toString());
pstmt = con.prepareStatement(sql.toString());
rs = pstmt.executeUpdate();
}catch( Throwable e ){
logger.error(e, e);
}finally{
if ( pstmt != null ){
try {
pstmt.close();
}
catch (Throwable ex) {
logger.error(ex, ex);
}
}
if ( con != null ){
try {
con.close();
}
catch (Throwable ex) {
logger.error(ex, ex);
}
}
}
//返回数据
return rs;
}
public SpBusinessObject[] getById(SpBusinessObject infovalue) throws SQLException {//查询所有数据
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
ArrayList list = new ArrayList();
try{
con = ConnectionManager.getInstance().getConnection(SpBusinessDao.class);
StringBuffer sql = new StringBuffer("select a.id,a.businessname,a.serviceid,");
sql.append( "a.isprepay");
sql.append( " from spbusiness a");
sql.append(" where 1=1");
if (infovalue!=null && infovalue.getID()!=null && !infovalue.getID().equals("")){
sql.append(" and a.id = '" + infovalue.getID() + "'");
}
logger.debug(sql.toString());
pstmt = con.prepareStatement(sql.toString());
rs = pstmt.executeQuery();
while (rs.next()){
SpBusinessObject model = new SpBusinessObject();
String id = rs.getString("id");
if (!rs.wasNull()) model.setID(id);
String businessname = rs.getString("businessname");
if (!rs.wasNull()) model.setBusinessName(businessname);
String serviceid = rs.getString("serviceid");
if (!rs.wasNull()) model.setServiceId(serviceid);
int isprepay = rs.getInt("isprepay");
if (!rs.wasNull()) model.setIsprepay(isprepay);
list.add(model);
}
}catch( Throwable e ){
logger.error(e, e);
}finally{
if ( rs != null ){
try {
rs.close();
}
catch (Throwable ex) {
logger.error(ex, ex);
}
}
if ( pstmt != null ){
try {
pstmt.close();
}
catch (Throwable ex) {
logger.error(ex, ex);
}
}
if ( con != null ){
try {
con.close();
}
catch (Throwable ex) {
logger.error(ex, ex);
}
}
}
//返回数据
logger.debug("12313123");
return (SpBusinessObject[])list.toArray(new SpBusinessObject[list.size()]);
}
static final Logger logger = Logger.getLogger(SpBusinessDao.class);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -