java - 导航按钮在java netbeans中不起作用
问题描述
我正在用 java 表单创建简单的 crud 系统,由 6 个按钮保存,第一个,下一个,上一个,最后一个我附上了表单设计下面的屏幕截图。如果单击保存按钮数据成功保存。然后如果我先单击第一个按钮显示记录,如果我单击最后一个按钮,最后一个记录应该成功显示。如果单击下一个并且上一个按钮数据无法正常工作。
下一个按钮代码是这个
String name = txtItem.getText();
int qty = Integer.parseInt(txtQty.getText());
int price = Integer.parseInt(txtPrice.getText());
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/supers","root","");
pst = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
String sql = "SELECT item,qty,price FROM stock";
ResultSet rs = pst.executeQuery(sql);
if (rs.next())
{
name = rs.getString("item");
qty = rs.getInt("qty");
price = rs.getInt("price");
txtItem.setText(name);
txtQty.setText(String.valueOf(qty));
txtPrice.setText(String.valueOf(price));
}
else
{
rs.previous();
JOptionPane.showMessageDialog(this,"end of the file");
}
} catch (ClassNotFoundException ex) {
Logger.getLogger(exmp.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(exmp.class.getName()).log(Level.SEVERE, null, ex);
}
解决方案
推荐阅读
- c# - Asp.Net Core [FromQuery] 绑定
- javascript - 如何使用javascript在文本框中15天后自动显示日期?
- java - 无法从 Eclipse 中的构建路径导入任何引用的库
- dart - Flutter:任何人都可以帮助在 Flutter 中制作自定义 TabController 吗?
- mysql - 如何在 Laravel SQL 查询中同时使用 `GroupBy` 和 `join`
- google-cloud-platform - 快照大小不一致
- sql - 为新恢复的数据库自动更改链接服务器名称
- c# - Lync-SDK MissingMethod-异常
- arrays - Swift 扩展仅适用于具有目标 c 元素的 Array 可能吗?
- awk - Grep 模式并在匹配模式之后选择 a 的一部分