我正在尝试在Access数据库上执行查询行,但我不能。
我正在使用UCanAccess连接数据库,并且运行连接的类运行正常,但是当我尝试使用prepareStatement
方法时,它会返回错误。
以下是代码:
String name = name_tx.getText();
String type = type_tx.getText();
String manuf = manu_tx.getText();
String model = model_tx.getText();
String serial = sn_tx.getText();
String dateOP = dop_tx.getText();
String supplier = supp_tx.getText();
String suppCNPJ = supp_cnpj_tx.getText();
String insEst = insEst_tx.getText();
String insMun = insMun_tx.getText();
String invNum = invNumb_tx.getText();
String warranty = warr_tx.getText();
try {
String query = "INSERT INTO IT_MATERIAL (Name, Type, Manufacturer, Model, Serial_Number, Dateof Purchase, Supplier, Supplier CNPJ, Inscricao Estadual, Inscricao Municipal, Invoice Number, Warranty Until) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
PreparedStatement st = con.prepareStatement(query);
st.setString(1, name);
st.setString(2, type);
st.setString(3, manuf);
st.setString(4, model);
st.setString(5, serial);
st.setString(6, dateOP);
st.setString(7, supplier);
st.setString(8, suppCNPJ);
st.setString(9, insEst);
st.setString(10, insMun);
st.setString(11, invNum);
st.setString(12, warranty);
ResultSet rs = st.executeQuery();
System.out.println(rs);
} catch(Exception ex) {
System.err.println("Error: " + ex);
}
这是一个按钮的操作,它将保存在数据库中,但它会返回以下错误消息。我试图弄清楚代码上的“Null”是什么,可能是在这段代码上,因为只有在你尝试使用按钮时才会发生;
显示java.lang.NullPointerException
StackTrace
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Frames.Init.insert_btMouseClicked(Init.java:235)
at Frames.Init.access$100(Init.java:18)
at Frames.Init$3.mouseClicked(Init.java:174)
at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:270)
at java.awt.Component.processMouseEvent(Component.java:6538)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6300)
at java.awt.Container.processEvent(Container.java:2236)
at java.awt.Component.dispatchEventImpl(Component.java:4891)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Component.dispatchEvent(Component.java:4713)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4534)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
at java.awt.Container.dispatchEventImpl(Container.java:2280)
at java.awt.Window.dispatchEventImpl(Window.java:2750)
at java.awt.Component.dispatchEvent(Component.java:4713)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)