SqlServer2005通过JTDS1.2.2取text字段值有问题
public IBean get(IBean obj, String[] attr) throws Exception { Object keyv = DMUtil.getkey(obj); OrderSplitDS ods = getCur_DS(obj,keyv); Connection conn = ods.getDs().getConnection(); PreparedStatement stm = null; ResultSet rs = null; try{ String att = (attr==null||attr.length<=0)?"*":StringUtils.join(attr, ","); stm = conn.prepareStatement("select "+att+" from " +obj.getTableName()+"_"+ods.getName()+"_"+ods.getCur_ds_index()+" where " +obj.getKeyField()+"=?"); stm.setObject(1, keyv); rs = stm.executeQuery(); if(rs.next()){ Method[] m = obj.getClass().getMethods(); for (int i = 0; i < m.length; i++) { String name = m[i].getName(); if(name.startsWith("set")&&m[i].getParameterTypes().length==1){ name = name.substring(3,name.length()); if(attr!=null&&attr.length>0&&(att.toLowerCase()+",").indexOf(name.toLowerCase()+",")<0){ continue; } try{ Object oo = rs.getObject(name); if(name.equals("edu")||name.equals("Edu")){ System.out.println(name+":"+oo); } if(oo==null) continue; if(oo instanceof ClobImpl){ ClobImpl coo = (ClobImpl)oo; oo = coo.getSubString(1, (int)coo.length()); System.out.println("------"+oo); }else if(m[i].getParameterTypes()[0].equals(Short.class)){ oo = Short.valueOf(oo.toString()); }else if(m[i].getParameterTypes()[0].equals(Byte.class)){ oo = Byte.valueOf(((Boolean)oo).booleanValue()?"1":"0"); } m[i].invoke(obj,new Object[]{oo}); }catch (Exception e) { e.printStackTrace(); } } } } }finally{ try{ if(rs!=null) rs.close(); }catch (Exception e) { } try{ if(stm!=null) stm.close(); }catch (Exception e) { } try{ if(conn!=null) conn.close(); }catch (Exception e) { } } return obj; }oo instanceof ClobImpl 永远进不去,
但是打印oo打印出 Edu:net.sourceforge.jtds.jdbc.ClobImpl@1008045 其实edu在数据库中是对应text字段的,怎样用JTDS把数据库中的text字段值取出来?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我记得直接 getString 就可以了
我记得直接 getString 就可以了