[英]ArrayIndexOutOfBoundsException while using prepared statement INSERT INTO
i am trying to insert these values into the table in the database, all values line up and are correctly spelt and ordered, this code has been working and i cannot for the life of me figure out why it is not now.我正在尝试将这些值插入数据库中的表中,所有值都排成一行并且拼写和排序正确,这段代码一直在工作,我一生都无法弄清楚为什么现在不行。 probably something silly but ive been over and over it with a fine tooth comb.
可能有些傻,但我用细齿梳一遍又一遍。 all variables have values.
所有变量都有值。
public void addNewProduct(int uuid, String location, String product, String category, int items, int numberOfBoxes, double price, String supplier, String value) throws SQLException {
try {
dbCon.NSStock();
dbAction = "INSERT INTO StockList (uuid, location, product, category, items, numberOfBoxes, price, supplier, value) VALUES (?,?,?,?,?,?,?,?,?)";
ps = dbCon.NSStock().prepareStatement(dbAction);
if(uuid == 0) {
uuid = createUUID();
}
ps.setInt(1, uuid);
ps.setString(2, location);
ps.setString(3, product);
ps.setString(4, category);
ps.setInt(5, items);
ps.setInt(6, numberOfBoxes);
ps.setDouble(7, price);
ps.setString(8, supplier);
ps.setString(9, value);
ps.executeUpdate();
JOptionPane.showMessageDialog(null, "Stock List Updated");
}catch(SQLException e) {
e.printStackTrace();
}finally{
dbCon.NSStock().close();
}
}
//exception details //异常详情
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
at org.sqlite.core.CorePreparedStatement.batch(CorePreparedStatement.java:130)
at org.sqlite.jdbc3.JDBC3PreparedStatement.setInt(JDBC3PreparedStatement.java:329)
at nightshelter.Stock.addNewProduct(Stock.java:84)
at nightshelter.NightShelterGUI.addNewProductBTNActionPerformed(NightShelterGUI.java:2587)
at nightshelter.NightShelterGUI.access$000(NightShelterGUI.java:27)
at nightshelter.NightShelterGUI$1.actionPerformed(NightShelterGUI.java:487)
at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967)
at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308)
at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279)
at java.desktop/java.awt.Component.processMouseEvent(Component.java:6636)
at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3342)
at java.desktop/java.awt.Component.processEvent(Component.java:6401)
at java.desktop/java.awt.Container.processEvent(Container.java:2263)
at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5012)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4844)
at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4918)
at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4547)
at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4488)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307)
at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2762)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4844)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
i moved the if statement out of the try/catch and now it works.我将 if 语句从 try/catch 中移出,现在它可以工作了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.