我似乎无法用我的JTable中给出的值更新我的数据库.
我的代码:
public void Update() throws SQLException
{
for (int a = 0; a < jTable1.getRowCount(); a++) {
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@//127.0.0.1:1521/xe","IND","pass");
Statement stmt = con.createStatement();
String query4 = "insert into MONTH_inv VALUES (?,?,?,?,?)";
String Category = jTable1.getValueAt(a, 0).toString();
String Item = jTable1.getValueAt(a, 1).toString();
int Quantity = Integer.parseInt((String) jTable1.getValueAt(a, 2));
int avg = Integer.parseInt((String) jTable1.getValueAt(a, 3));
int ground = Integer.parseInt((String) jTable1.getValueAt(a, 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();
}
}
Run Code Online (Sandbox Code Playgroud)
一切都运行正常,但当我点击我的GUI上的UPDATE按钮时,我收到错误: …