可能重复:
How to Display next and previous records on clicking on next button in Java
我正在尝试将数据库中的记录显示到JAVA中的gui应用程序中。我尝试运行下面的代码,但后来我得到了不支持操作的异常,不知道它有什么问题。
private void bt_previousActionPerformed(java.awt.event.ActionEvent evt) {
if(evt.getSource()==bt_previous){
DBUtil util = new DBUtil();
try {
Connection con = util.getConnection();
PreparedStatement stmt = con.prepareStatement("SELECT [box_no],[weight],[note_state],[dm_state],[1],[2],[5],[10],[20],[50],[100],[500],[1000] FROM [CNV].[dbo].[soil_det] where rm_id=?");
ResultSet rs;
String rm = tf_rm_id.getText().trim();
stmt.setLong(1, Long.parseLong(rm));
rs = stmt.executeQuery();
rs.getArray(WIDTH);
char n = WIDTH;
int i;
for (i=0; i<n; i++) {
String a = rs.getString("weight");
txtboxwgt.setText(a);
String b = rs.getString("note_state");
cbnotstat.setSelectedItem(b);
String c = rs.getString("dm_state");
cbdmnstat.setSelectedItem(c);
txtboxno.setText(rs.getString("box_no"));
txtRe1.setText(rs.getString("1"));
txtRs2.setText(rs.getString("2"));
txtRs5.setText(rs.getString("5"));
txtRs10.setText(rs.getString("10"));
txtRs20.setText(rs.getString("20"));
txtRs50.setText(rs.getString("50"));
txtRs100.setText(rs.getString("100"));
txtRs500.setText(rs.getString("500"));
txtRs1000.setText(rs.getString("1000"));
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage());
}
}
}
答案 0 :(得分:3)