SqlServer2005通过JTDS1.2.2取text字段值有问题

wrean2013 发布于 2012/06/14 09:54
阅读 472
收藏 0
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字段值取出来?

加载中
0
鉴客
鉴客

我记得直接 getString 就可以了

0
wrean2013
wrean2013

引用来自“鉴客”的答案

我记得直接 getString 就可以了

试过了,如果是数据库是text,rs.getObject取出来就是Blob,直接转String会报错啊
返回顶部
顶部