您好我是java的新手,我无法弄清楚如何使用在Jtable中输入的值更新我的数据库。我的代码:
public void Update() throws SQLException {
for (int i = 0; i < jTable1.getRowCount(); i++) {
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@//127.0.0.1:1521/xe", "IND", "password");
Statement stmt = con.createStatement();
String query4 = "Insert into MONTH_inv VALUES (?,?,?,?,?)";
String Category = jTable1.getValueAt(i, 0).toString();
String Item = jTable1.getValueAt(i, 1).toString();
int Quantity = Integer.parseInt((String) jTable1.getValueAt(i, 2));
int avg = Integer.parseInt((String) jTable1.getValueAt(i, 3));
int ground = Integer.parseInt((String) jTable1.getValueAt(i, 4));
PreparedStatement pstmt = con.prepareStatement(query4);
pstmt.setString(1, Category);
pstmt.setString(2, Item);
pstmt.setInt(3, Quantity);
pstmt.setInt(4, avg);
pstmt.setInt(5, ground);
pstmt.executeUpdate();
}
}
我收到错误: 并非所有变量都绑定
我不知道该怎么办。我认为我从每个单元格声明每个变量的方式是错误的,但我需要帮助
[编辑] 我尽我所能,但现在我得到了错误: 线程“AWT-EventQueue-0”中的异常java.lang.NumberFormatException:null