码迷,mamicode.com
首页 > 数据库 > 详细

数据库中数字和中文的转换问题

时间:2018-05-25 19:30:07      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:end   汉字   rac   for循环   ati   利用   public   cep   and   

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>");

  

数据库中数字和中文的转换问题

标签:end   汉字   rac   for循环   ati   利用   public   cep   and   

原文地址:https://www.cnblogs.com/demon09/p/9090025.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!