如何在单击Java中的下一个按钮时显示下一个和上一个记录 [英] How to Display next and previous records on clicking on next button in Java
问题描述
Hello Friends我试图在我的Jave Gui应用程序中显示记录我已经制作了一些代码但是当我点击下一个按钮时它会显示最后一条记录。有没有其他方法来查看请帮助之间的记录。
Hello Friends I am trying to diplay the records in my Jave Gui Application I have made some code it works but when I click on next button it displays the last record. Is there any another way to view the records present in between please help.
private void bt_nextActionPerformed(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();
while (rs.next()) {
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());
}
}
}`enter code here`
推荐答案
您需要将数据库代码与GUI代码分开。您还需要将应用程序分解为更小,更容易编码的步骤。
You need to separate your database code from your GUI code. You also need to break up your application into smaller, more easily coded steps.
以下是应用程序在启动时需要执行的操作:
Here are the things that your application needs to do when starting:
- 打开与数据库的连接。
- 选择表soil_det的所有键,并将键保存在列表。
- 选择第一行,然后显示它。
当下一个按钮是左键单击:
When the next button is left clicked:
- 从列表中获取下一个键。
- 如果你'显示一条消息'超过列表的末尾。
- 否则,选择当前行并显示它。
当点击上一个按钮时:
- 从列表中获取上一个键。
- 如果您已经超过列表的开头,则显示一条消息。
- 否则,选择当前行并显示它。
以下是您的应用程序需要执行的操作母鸡结束:
Here are the things that your application needs to do when ending:
- 关闭与数据库的连接。
这篇关于如何在单击Java中的下一个按钮时显示下一个和上一个记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!