1. 程式人生 > >【java】arcII碼為0x01,0x02作為分隔符

【java】arcII碼為0x01,0x02作為分隔符

不知道大家在拼接字串的時候是怎麼做的?是不是採用,或:? 
這樣做有的時候不很安全,因為你不能確保你傳入的字串中沒有這幾個字元,那怎麼做能保證萬無一失呢? 

arcII碼為0x01,0x02的字元是鍵盤所不能輸入的,因為用這個能保證萬無一失。 

public String GetEnterpriseInfo(String code) {
		
		Connection cn = null;
		PreparedStatement stm = null;
		ResultSet rs = null;
		String s = "";
		byte  b1[] = {0x02};
		byte  b2[] = {0x01};
		String str1 = new String(b1); 
		String str2 = new String(b2); 
		try {
			cn = DBUtil.getConn();
			String sql = "select station_id,station_desc from  t_cfg_station_info where area_id like '%"+code+"%'";
			stm = cn.prepareStatement(sql);
			rs = stm.executeQuery();
			while(rs.next()){
				s += rs.getString(1)+str1+rs.getString(2)+str2;
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			DBUtil.close(rs, stm, cn);
		}
		return s;
	}