zoukankan      html  css  js  c++  java
  • 数据库中数字和中文的转换问题

    public class DaoUtil{
        /**
    	 * 系统字典表
    	 * 适用于列表循环时,根据编码获取汉字
    	 * @param appdicid
    	 * @return
    	 */
    	public static Hashtable<String, String> getOptionHashtable(String appdicid){
    		Connection conn = DBSql.open();
    		try {
    			return getOptionHashtable(conn, appdicid);
    		} finally {
    			DBSql.close(conn, null, null);
    		}
    	}
    
    	/**
    	 * 系统字典表
    	 * 适用于列表循环时,根据编码获取汉字
    	 * @param conn
    	 * @param appdicid
    	 * @return
    	 */
    	public static Hashtable<String, String> getOptionHashtable(Connection conn, String appdicid){
    		Hashtable<String, String> ht = new Hashtable<String, String>();
    		Statement st = null;
    		ResultSet rs = null;
    		try {
    			st = conn.createStatement();
    			rs = st.executeQuery("select dicname,dicvalue from sys_dic where appdicid='"
    					+appdicid+"' and isleaf='1'");
    			while(rs.next()){
    				ht.put(rs.getString("dicvalue"), rs.getString("dicname"));
    			}
    		} catch (SQLException e) {
    			e.printStackTrace();
    		} finally {
    			DBSql.close(st, rs);
    		}
    		return ht;
    	}
    }
    //从数据库中使用select查出的CONTRACTCONTENT字段存储的是数字,利用for循环,从Hashtable中的使用ht.get("CONTRACTCONTENT")取出来的是数字,此时,无需使用if(){}else{}判断,
    调用上述方法即可实线中文的转换:
    Hashtable<String, String> contractcontents = DaoUtil.getOptionHashtable("7017"); 
    //展示列表页面:
    //使用append追加列表
    sb.append("<td width="8%" class="t1-12">").append(DaoUtil.nullToNBSP(contractcontents.get(DaoUtil.nullToString(ht.get("CONTRACTCONTENT"))))).append("</td>");
    

      

  • 相关阅读:
    centos8.2安装nginx
    Centos8安装PostgreSQL
    PostgreSQL 安装时提示下载元数据失败
    MySQL8定时备份
    Centos8安装Docker
    Centos8安装中文字体
    Centos8源码安装libgdiplus
    MySQL拖拽排序
    MySQL8修改事务隔离级别
    MySQL启动问题
  • 原文地址:https://www.cnblogs.com/demon09/p/9090025.html
Copyright © 2011-2022 走看看