我有一个jTable,当应用程序运行时,用数据库项填充它。现在我已经创建了一个保存按钮,可以修改更改并将其保存到数据库中,但我一直收到一个我无法弄清楚的错误。
按钮:
private void btnOpslaanActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int row = jTable1.getSelectedRow();
int col = jTable1.getSelectedColumn();
int category_id = (Integer)(jTable1.getValueAt(row, 1));
String name = jTable1.getValueAt(row, 2).toString();
double price = (Double)jTable1.getValueAt(row, 3);
String description = jTable1.getValueAt(row, 4).toString();
queryManager.updateProductList(category_id, name, price, description);
}
变量在系统输出时经过测试更新(这样工作正常) 我收到了这一行的错误:
queryManager.updateProductList(category_id, name, price, description);
queryManager.updateProductList方法:
public void updateProductList(int category_id, String name, double price, String description){
String sql ="UPDATE product SET categorie_id='" +category_id+ "', naam='" +name+ "', prijs='" +price+ "', omschrijving='"+description+"'";
ResultSet result = dbmanager.doQuery(sql);
try {
result.next();
} catch (SQLException e) {
System.out.println("Productlijst updaten is niet gelukt: " + e.getMessage());
}
}
希望有人能帮我解决这个问题!还有我得到的错误:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at view.ShowProductList.btnOpslaanActionPerformed(ShowProductList.java:162)
at view.ShowProductList.access$400(ShowProductList.java:19)
at view.ShowProductList$6.actionPerformed(ShowProductList.java:108)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2351)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6382)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3275)
at java.awt.Component.processEvent(Component.java:6147)
at java.awt.Container.processEvent(Container.java:2083)
at java.awt.Component.dispatchEventImpl(Component.java:4744)
at java.awt.Container.dispatchEventImpl(Container.java:2141)
at java.awt.Component.dispatchEvent(Component.java:4572)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4619)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4280)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4210)
at java.awt.Container.dispatchEventImpl(Container.java:2127)
at java.awt.Window.dispatchEventImpl(Window.java:2489)
at java.awt.Component.dispatchEvent(Component.java:4572)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:704)
at java.awt.EventQueue.access$400(EventQueue.java:82)
at java.awt.EventQueue$2.run(EventQueue.java:663)
at java.awt.EventQueue$2.run(EventQueue.java:661)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
at java.awt.EventQueue$3.run(EventQueue.java:677)
at java.awt.EventQueue$3.run(EventQueue.java:675)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:674)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
答案 0 :(得分:1)
可能“queryManager”未正确解析。 您是否尝试过调试代码?