他会出现Column Index out of range6>5这个错误,本人萌新,不懂怎么解决,求大佬

w2369498617 2019-02-18 08:11:30
public List<Object> showOrders(int userId) {
List<Object> list = new ArrayList<>();
List<String> namelist = new ArrayList<>();
List<Orders> olist = new ArrayList<>();
conn = DbConn.getConn();
try {
st = conn.createStatement();
String sql = "select u.name,f.address,o.date,o.num,o.money from orders o,fare f ,user u where o.fareid=f.id and o.userid=u.id and o.userid="+userId+"";
rs = st.executeQuery(sql);
while (rs.next()) {
String name = rs.getString(1);
String date = rs.getString(3);
int num = rs.getInt(5);
double money=rs.getDouble(6);
Orders o = new Orders(0, userId, 0, date, num, money);
olist.add(o);
namelist.add(name);
}
list.add(olist);
list.add(namelist);
return list;
} catch (Exception e) {
e.printStackTrace();
} finally {
DbConn.closeDbconn(conn, st, rs);
}
return null;
}




/**查看订单*/
public void showOrders() {
int userId=manageController.showId(names);
List<Object> list= orderController.showOrders(userId);
if(list==null) {
System.out.println("您还没有购买过车票!");
}else {
List<String> nameList=(List<String>) list.get(1);
List<Orders> olist=(List<Orders>) list.get(0);
System.out.println("用户姓名\t\t车票地址\t\t购买时间\t\t\t购买数量\t\t消费金额");
for (int i = 0; i < nameList.size(); i++) {
if(nameList.get(i)!=null) {
String name=nameList.get(i);
Orders o=olist.get(i);
System.out.println(name+"\t\t"+o.getFareid()+"\t\t"+o.getDate()+"\t\t\t"+o.getNum()+"\t\t"+o.getMoney());
}else {
System.out.println("您未购买过车票");
}
}
}
}
...全文
633 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
咸哼酒家 2019-02-19
  • 打赏
  • 举报
回复
double money=rs.getDouble(6);
结果集只有5个参数,你取第6个自然报错了
usecf 2019-02-19
  • 打赏
  • 举报
回复
这个错误提示是数组越界了
一般都是索引从0开始的 检查下你代码double money=rs.getDouble(6);看看你这块对不对是6还是5
w2369498617 2019-02-19
  • 打赏
  • 举报
回复
谢谢 问题解决了

58,454

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧