[mysql] JDBC访问MySql解决方案-请补充下查询出来的信息如何解析!

humengpro 2012-06-24

如下代码有点太粗了,能提供个更方便的解决方案吗,类似hibernate,直接获取某指定的值

        try { 
            List<Object[]> list = ConnectionManager.excuteQuery("select * from t"); 
            for (int i = 0; i < list.size(); i++) { 
                Object[] os = list.get(i); 
                for(Object o : os){ 
                    if (o instanceof String) { 
                        String s = (String) o; 
                        String newStr = new String(s.getBytes("ISO-8859-1"),"GBK"); 
                        System.out.print("字符串:" + newStr + "\t\t"); 
                    }else if(o instanceof Long){ 
                        Long s = (Long) o; 
                        System.out.print("浮点值:" + s + "\t\t"); 
                    }else if(o instanceof Integer){ 
                        Integer s = (Integer) o; 
                        System.out.print("整形值:" + s + "\t\t"); 
                    }else{ 
                        System.out.print("未知型:" + o + "\t\t"); 
                    } 
                } 
                System.out.println(); 
            } 
        } catch (Exception e) { 
            e.printStackTrace(); 
        }        
humengpro 2012-06-24
有用JDBC读数据库的,参考下这个,写的不错
http://www.blogjava.net/myfly/archive/2008/09/18/229802.html
Global site tag (gtag.js) - Google Analytics