62,614
社区成员
发帖
与我相关
我的任务
分享
Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager.getConnection("jdbc:mysql://localhost/tablesys?" + "user=test&password=123");
preparedStatement = connect.prepareStatement("select * from tablesys.booking ");
ResultSet rs = preparedStatement.executeQuery();
rs.last(); //移到最后一行
int count = rs.getRow(); //得到当前行号,也就是记录数
rs.beforeFirst(); //还要用到记录集,就把指针再移到初始化的位置
Object[][] info = new Object[count][6];
while(rs.next()){//这里没有进入
info[count][0] = rs.getString("date")+ " " +rs.getString("time");
info[count][1] = rs.getString("name");
info[count][2] = rs.getString("peopleamout");
info[count][3] = Integer.valueOf( rs.getInt("tableid"));
info[count][4] = rs.getString("phone");
info[count][5] = Integer.valueOf( rs.getInt("bookingid") );
}
MyTableModel model = new MyTableModel(info, new String[]{
"Time", "Name", "Covers", "Table No", "Phone", "BookingID"
});
jTable1.setModel(model);
} catch (Exception ex) {
Logger.getLogger(MainMenu.class.getName()).log(Level.SEVERE, null, ex);
}
Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager.getConnection("jdbc:mysql://localhost/tablesys?" + "user=test&password=123");
preparedStatement = connect.prepareStatement("select * from tablesys.booking ");
ResultSet rs = preparedStatement.executeQuery();
int count = 0;
Object[][] info = new Object[count][6];
while(rs.next()){
info[count][0] = rs.getString("date")+ " " +rs.getString("time");
info[count][1] = rs.getString("name");
info[count][2] = rs.getString("peopleamout");
info[count][3] = Integer.valueOf( rs.getInt("tableid"));
info[count][4] = rs.getString("phone");
info[count][5] = Integer.valueOf( rs.getInt("bookingid") );
count++;
}
MyTableModel model = new MyTableModel(info, new String[]{
"Time", "Name", "Covers", "Table No", "Phone", "BookingID"
});
jTable1.setModel(model);
} catch (Exception ex) {
Logger.getLogger(MainMenu.class.getName()).log(Level.SEVERE, null, ex);
}
Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager.getConnection("jdbc:mysql://localhost/tablesys?" + "user=test&password=123");
preparedStatement = connect.prepareStatement("select * from tablesys.booking ");
ResultSet rs = preparedStatement.executeQuery();
int count = 0;
// Object[][] info = new Object[count][6];//这里不一定非得用数组的。改成List<E>形式的
//改成这种形式
List<Object[]> list=new ArrayList<Object[]>();
while(rs.next()){
Object[] info=new Object[6];
info[0] = rs.getString("date")+ " " +rs.getString("time");
info[1] = rs.getString("name");
info[2] = rs.getString("peopleamout");
info[3] = Integer.valueOf( rs.getInt("tableid"));
info[4] = rs.getString("phone");
info[5] = Integer.valueOf( rs.getInt("bookingid") );
list.add(info);
}
MyTableModel model = new MyTableModel(info, new String[]{
"Time", "Name", "Covers", "Table No", "Phone", "BookingID"
});
jTable1.setModel(model);
} catch (Exception ex) {
Logger.getLogger(MainMenu.class.getName()).log(Level.SEVERE, null, ex);
}
Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager.getConnection("jdbc:mysql://localhost/tablesys?" + "user=test&password=123");
preparedStatement = connect.prepareStatement("select * from tablesys.booking ");
ResultSet rs = preparedStatement.executeQuery();
int count = 0;
Object[][] info = new Object[count][6];
while(rs.next()){
count++;
info[count][0] = rs.getString("date")+ " " +rs.getString("time");
info[count][1] = rs.getString("name");
info[count][2] = rs.getString("peopleamout");
info[count][3] = Integer.valueOf( rs.getInt("tableid"));
info[count][4] = rs.getString("phone");
info[count][5] = Integer.valueOf( rs.getInt("bookingid") );
}
MyTableModel model = new MyTableModel(info, new String[]{
"Time", "Name", "Covers", "Table No", "Phone", "BookingID"
});
jTable1.setModel(model);
} catch (Exception ex) {
Logger.getLogger(MainMenu.class.getName()).log(Level.SEVERE, null, ex);
}
Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager.getConnection("jdbc:mysql://localhost/tablesys?" + "user=test&password=123");
preparedStatement = connect.prepareStatement("select * from tablesys.booking ");
ResultSet rs = preparedStatement.executeQuery();
int count = 0;
while(rs.next()){// 这里已经迭代完了,所以下面2处没有了
count++;
}
Object[][] info = new Object[count][6];
rs = preparedStatement.executeQuery();
while(rs.next()){//这里没有进入
info[count][0] = rs.getString("date")+ " " +rs.getString("time");
info[count][1] = rs.getString("name");
info[count][2] = rs.getString("peopleamout");
info[count][3] = Integer.valueOf( rs.getInt("tableid"));
info[count][4] = rs.getString("phone");
info[count][5] = Integer.valueOf( rs.getInt("bookingid") );
}
MyTableModel model = new MyTableModel(info, new String[]{
"Time", "Name", "Covers", "Table No", "Phone", "BookingID"
});
jTable1.setModel(model);
} catch (Exception ex) {
Logger.getLogger(MainMenu.class.getName()).log(Level.SEVERE, null, ex);
}
Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager.getConnection("jdbc:mysql://localhost/tablesys?" + "user=test&password=123");
preparedStatement = connect.prepareStatement("select * from tablesys.booking ");
ResultSet rs = preparedStatement.executeQuery();
int count = 0;
while(rs.next()){// 这里已经迭代完了,所以下面2处没有了
count++;
}
Object[][] info = new Object[count][6];
while(rs.next()){//这里没有进入
info[count][0] = rs.getString("date")+ " " +rs.getString("time");
info[count][1] = rs.getString("name");
info[count][2] = rs.getString("peopleamout");
info[count][3] = Integer.valueOf( rs.getInt("tableid"));
info[count][4] = rs.getString("phone");
info[count][5] = Integer.valueOf( rs.getInt("bookingid") );
}
MyTableModel model = new MyTableModel(info, new String[]{
"Time", "Name", "Covers", "Table No", "Phone", "BookingID"
});
jTable1.setModel(model);
} catch (Exception ex) {
Logger.getLogger(MainMenu.class.getName()).log(Level.SEVERE, null, ex);
}