如下:
- 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()+"" 这样可以转成串