commoncodedao.java

来自「一个常用的电子商城的站点源码」· Java 代码 · 共 97 行

JAVA
97
字号
package com.publish.shop.util.dao;import java.sql.*;import java.util.ArrayList;import com.publish.shop.util.db.DbPool;import com.publish.shop.util.javabeans.*;import org.apache.struts.util.LabelValueBean;/** * 锟斤拷锟矫达拷锟斤拷锟紻AO锟斤拷锟斤拷莶锟斤拷锟斤拷锟\uFFFD * @author david * @version 1.0 */public class CommonCodeDAO{    public ArrayList getCommonCodeLabel(String codeType) {        ArrayList list = new ArrayList();        String sql = "select CodeName,CodeValue from CommonCode_table"                     + " where CodeType = '"+codeType+"'"                     + " order by CodeName";        ResultSet rs = null;        Statement stmt = null;        Connection con = null;        try{          con = DbPool.getConnection();          stmt = con.createStatement();          rs = stmt.executeQuery(sql);          while(rs.next()){             String CodeName = rs.getString(1).trim();             String description = rs.getString(2).trim();             LabelValueBean label = new LabelValueBean(description,CodeName);             list.add(label);          }        }catch(Exception e){            e.printStackTrace();        }        finally{          DbPool.closeResultSet(rs);          DbPool.closeStatement(stmt);          DbPool.closeConnection(con);        }        return list;    }    public String getCommonCodeDescription(String codeType,String codeName) {        String description = "";        String sql = "select CodeValue from Common_Code"                     + " where CodeName = '"+codeName+"'"                     + " and CodeType = '"+codeType+"'";        ResultSet rs = null;        Statement stmt = null;        Connection con = null;        try{            con = DbPool.getConnection();            stmt = con.createStatement();            rs = stmt.executeQuery(sql);            while(rs.next()){                 description = rs.getString(1);            }        }catch(java.sql.SQLException sqlEx){           sqlEx.printStackTrace();        }catch(Exception e){            e.printStackTrace();        }        finally{          DbPool.closeResultSet(rs);          DbPool.closeStatement(stmt);          DbPool.closeConnection(con);        }        return description;    }    public String getCommonCodeDescription(Connection con,String codeType,int codeName) {        String description = "";        String sql = "select CodeValue from Common_Code"                     + " where CodeName = '"+codeName+"'"                     + " and CodeType = '"+codeType+"'";        ResultSet rs = null;        Statement stmt = null;        try{            stmt = con.createStatement();            rs = stmt.executeQuery(sql);            while(rs.next()){                 description = rs.getString(1);            }        }catch(java.sql.SQLException sqlEx){            sqlEx.printStackTrace();        }        finally{          DbPool.closeResultSet(rs);          DbPool.closeStatement(stmt);        }        return description;    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?