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

Java codepublic 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

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

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();

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
import java.sql.; public class lianjie { // JDBC连接MySQL的URL、用户名和密码 static final String JDBC_URL = "jdbc:mysql://localhost:3306/sys?serverTimezone=GMT%2B8&useSSL=false"; static final String USERNAME = "root"; static final String PASSWORD = "zoushenyu"; public static void main(String[] args) throws SQLException { Connection conn = null; Statement stmt = null; ResultSet rs = null; try { // 连接MySQL数据库 conn = DriverManager.getConnection(JDBC_URL, USERNAME, PASSWORD); // 插入数据 stmt = conn.createStatement(); String sql = "INSERT INTO guoguan (id, name, age, birthday, salary) VALUES (105, '张三', 20, '2000-01-01', 4300)"; stmt.executeUpdate(sql); // 修改数据 sql = "UPDATE guoguan SET salary = 4500 WHERE id = 105"; stmt.executeUpdate(sql); // 删除数据 / sql = "DELETE FROM guoguan WHERE id = 105"; stmt.executeUpdate(sql);*/ // 查询数据 sql = "SELECT * FROM guoguan"; rs = stmt.executeQuery(sql); while (rs.next()) { int id = rs.getInt("id"); String name = rs.getString("name"); int age = rs.getInt("age"); Date birthday = rs.getDate("birthday"); double salary = rs.getDouble("salary"); System.out.printf("%d %s %d %s %.2f\n", id, name, age, birthday.toString(), salary); } } catch (SQLException e) { e.printStackTrace(); } finally { // 释放资源 if (rs != null) { rs.close(); } if (stmt != null) { stmt.close(); } if (conn != null) { conn.close(); } } } } use sys; create table guoguan( id int, name varchar(40), age int, birthday date, salary double ); select * from guoguan; 请为这两份代码写一段说明文档,要尽量详细
06-10

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值