当前位置: 代码迷 >> Java Web开发 >> colText[i] = rs.getInt(i).toString; //异常:无法取消引用int: 怎么处理?
  详细解决方案

colText[i] = rs.getInt(i).toString; //异常:无法取消引用int: 怎么处理?

热度:7204   发布时间:2013-02-25 21:15:35
colText[i] = rs.getInt(i).toString; //错误:无法取消引用int: 怎么办??
如下:
Java code
public class test5{        public test5(){        Object key=null;        Object value=null;        Map map=new HashMap();        List list=new ArrayList();        String connUrl = "jdbc:odbc:Driver={MicroSoft Excel Driver (*.xls)};DBQ=D:/Tomcat 6.0/webapps/myapp/db1.xls";          String dbDrv = "sun.jdbc.odbc.JdbcOdbcDriver";           String[] colName=null;        String[] colText=null;        Connection con = null;        Statement ps=null;        ResultSet rs=null;        try{              Class.forName(dbDrv).newInstance();              con = DriverManager.getConnection(connUrl);              ps=con.createStatement();                   rs=ps.executeQuery("select * from [sheet1$]");                              rs.next();                   colName=new String[17];                  colText=new String[17];                            for (int i=1;i<colName.length;i++){                                 if(rs.getMetaData().getColumnType(i)==Types.INTEGER){                             colText[i] = rs.getInt(i).toString;         //错误:无法取消引用int                          }else{                             colText[i] = rs.getString(i);                             }                                  colName[i]=rs.getMetaData().getColumnName(i);                  }                                                          for (int i=1;i<colName.length;i++){                                                   map.put(colName[i],colText[i]);                         }                                  list.add(map);                            }catch(Exception ex){               ex.printStackTrace();           }                                                            System.out.println(map.size());                      }                            public static void main(String args[]){                   new test5();      }}        


------解决方案--------------------------------------------------------
int没有toString方法, Integer才有.!
LZ可以这样 getInt()+"" 这样可以转成串
  相关解决方案