DAO >>>>>
String destValue = "";
Connection con = null;
Statement st = null;
ResultSet rs = null;
try {
con = this.getSqlMapClientTemplate().getDataSource().getConnection();
st = con.createStatement();
rs = st.executeQuery(isql);
while(rs.next()){
log.info(rs.getObject(1));
Object rsobj =rs.getObject(1);
if(rsobj instanceof Integer){
log.info("111");
Integer integer = (Integer)rsobj;
destValue = integer.toString();
}else if(rsobj instanceof Long){
log.info("222");
Long l = (Long)rsobj;
destValue = l.toString();
}else if(rsobj instanceof java.math.BigDecimal){
log.info("333");
java.math.BigDecimal b = (java.math.BigDecimal) rsobj;
destValue = b.toString();
}else if(rsobj instanceof java.sql.Date){
log.info("444");
destValue = rsobj.toString();
}else if(rsobj instanceof java.sql.Timestamp){
log.info("555");
Date date = (Date) rsobj;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
destValue = sdf.format(date).toString();
}else if(rsobj instanceof java.sql.Clob){
log.info("666");
String reString = "";
java.sql.Clob clob = (java.sql.Clob)rsobj;
if (clob != null){
//try {
Reader is = clob.getCharacterStream();// 得到流
BufferedReader br = new BufferedReader(is);
String s = br.readLine();
StringBuffer sb = new StringBuffer();
while (s != null) {// 执行循环将字符串全部取出付值给StringBuffer由StringBuffer转成STRING
sb.append(s);
s = br.readLine();
}
reString = sb.toString();
//} catch (SQLException e) {
// logger.error("ClobToString SQLException:", e);
//} catch (IOException e) {
// logger.error("ClobToString IOException:", e);
//}
}
destValue = reString;
}else{
log.info("777");
destValue = (String) rsobj;
}
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
rs.close();
st.close();
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
/* if(isql.indexOf("l.accountflag = '1' or l.accountflag = '2'")!=-1){
isql = isql.replace("( l.accountflag = '1' or l.accountflag = '2' )",
"l.accountflag in ( '1','2')");
}*/
/* log.warn("isql2:" + isql);
Map condition = new HashMap();
if (isql != null && !"".equals(isql)) {
condition.put("sql", isql);
} else {
condition.put("sql", null);
}
List iList = this.getSqlMapClientTemplate().queryForList("findDestValueBySql",condition);
String destValue = "";
for(Object rsobj : iList){
if(rsobj != null){
HashMap hashMap = (HashMap) rsobj;
Set set = hashMap.entrySet();
Iterator iterator = set.iterator();
while (iterator.hasNext()) {
Map.Entry mapentry = (Map.Entry) iterator.next();
System.out.println(mapentry.getKey() + "/" + mapentry.getValue());
rsobj = mapentry.getValue();
if(rsobj instanceof Integer){
log.info("111");
Integer integer = (Integer)rsobj;
destValue = integer.toString();
}else if(rsobj instanceof Long){
log.info("222");
Long l = (Long)rsobj;
destValue = l.toString();
}else if(rsobj instanceof java.math.BigDecimal){
log.info("333");
java.math.BigDecimal b = (java.math.BigDecimal) rsobj;
destValue = b.toString();
}else if(rsobj instanceof java.sql.Date){
log.info("444");
destValue = rsobj.toString();
}else if(rsobj instanceof java.sql.Clob){
String reString = "";
java.sql.Clob clob = (java.sql.Clob)rsobj;
if (clob != null){
//try {
Reader is = clob.getCharacterStream();// 得到流
BufferedReader br = new BufferedReader(is);
String s = br.readLine();
StringBuffer sb = new StringBuffer();
while (s != null) {// 执行循环将字符串全部取出付值给StringBuffer由StringBuffer转成STRING
sb.append(s);
s = br.readLine();
}
reString = sb.toString();
//} catch (SQLException e) {
// logger.error("ClobToString SQLException:", e);
//} catch (IOException e) {
// logger.error("ClobToString IOException:", e);
//}
}
destValue = reString;
}else{
log.info("555");
destValue = (String) rsobj;
}
}
}
}*/
/*
Set set = hashMap.entrySet();
Iterator iterator = set.iterator();
String destValue = "";
while (iterator.hasNext()) {
Map.Entry mapentry = (Map.Entry) iterator.next();
System.out.println(mapentry.getKey() + "/" + mapentry.getValue());
Object rsobj = mapentry.getValue();
if(rsobj != null){
if(rsobj instanceof Integer){
log.info("111");
Integer integer = (Integer)rsobj;
destValue = integer.toString();
}else if(rsobj instanceof Long){
log.info("222");
Long l = (Long)rsobj;
destValue = l.toString();
}else if(rsobj instanceof java.math.BigDecimal){
log.info("333");
java.math.BigDecimal b = (java.math.BigDecimal) rsobj;
destValue = b.toString();
}else if(rsobj instanceof java.sql.Date){
log.info("444");
destValue = rsobj.toString();
}else if(rsobj instanceof java.sql.Clob){
String reString = "";
java.sql.Clob clob = (java.sql.Clob)rsobj;
if (clob != null){
//try {
Reader is = clob.getCharacterStream();// 得到流
BufferedReader br = new BufferedReader(is);
String s = br.readLine();
StringBuffer sb = new StringBuffer();
while (s != null) {// 执行循环将字符串全部取出付值给StringBuffer由StringBuffer转成STRING
sb.append(s);
s = br.readLine();
}
reString = sb.toString();
//} catch (SQLException e) {
// logger.error("ClobToString SQLException:", e);
//} catch (IOException e) {
// logger.error("ClobToString IOException:", e);
//}
}
destValue = reString;
}else{
log.info("555");
destValue = (String) rsobj;
}
}
}*/
return destValue;
搞了好久,,,
开始想配sqlmap
<select id="findDestValueBySql" parameterClass="java.util.HashMap" remapResults="true"
resultClass="java.util.HashMap">
$sql$
</select>
普通语句可以通过,但是稍微复杂的sql就报错,什么Object里面没有这个字段,,,那个字段却是我sql的一个片段,
queryForList queryForMap queryForObject 各种测试未果,,最后只能改成最开始写的那样,,,