try {
int rows = jTableA.getRowCount();
Class.forName("org.apache.derby.jdbc.ClientDriver");
con = DriverManager.getConnection("jdbc:derby://localhost:1527/meinedb", "root", "root123");
Statement st = con.createStatement();
String delete = "DELETE FROM ROOT.ARTIKEL";
st.execute(delete);
int b = 0;
for (int row = 0; row < rows; row++) {
Integer artikelnummer = (Integer) jTableA.getValueAt(row, 0);
String beschreibung = (String) jTableA.getValueAt(row, 1);
String bestellenbei = (String) jTableA.getValueAt(row, 2);
Integer menge = (Integer) jTableA.getValueAt(row, 3);
String bestellenbis = (String) jTableA.getValueAt(row, 4);
Boolean bestellt = (Boolean) jTableA.getValueAt(row, 5);
if (bestellt == true) {
b = 1;
}
if (bestellt == false) {
b = 0;
}
String sql ="INSERT INTO ROOT.ARTIKEL (ARTIKELNUMMER, BESCHREIBUNG, BESTELLENBEI, "
+ "ARTIKELMENGE, BESTELLENBIS, BESTELLT)"
+ " VALUES ('"+artikelnummer+"', '"+beschreibung+"', '"+bestellenbei+"', '"+menge+"',"
+ " '"+bestellenbis+"', '"+bestellt+"')" ;
st.execute(sql);
}
JOptionPane.showMessageDialog(null, "Artikel erfolgreich gespeichert");
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Speichern Fehlgeschlagen");
}
例外:
运行: Mär29,2019 1:17:41 PM Auftrags.Datenbank SpeichernA SCHWERWIEGEND:空 java.sql.SQLSyntaxErrorException:Spalten vom Typ'INTEGER'dürfenkeine Werte des Typs'CHAR'引起的。 在org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(未知来源) 在org.apache.derby.client.am.SqlException.getSQLException(未知来源) 在org.apache.derby.client.am.Statement.execute(未知来源) 在Auftrags.Datenbank.SpeichernA(Datenbank.java:135) 在Auftrags.MainWindow.jBsaveOrderActionPerformed(MainWindow.java:1567) 在Auftrags.MainWindow.access $ 4800(MainWindow.java:19) 在Auftrags.MainWindow $ 49.actionPerformed(MainWindow.java:857) 在javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022) 在javax.swing.AbstractButton $ Handler.actionPerformed(AbstractButton.java:2348) 在javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402) 在javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259) 在javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252) 在java.awt.Component.processMouseEvent(Component.java:6539) 在javax.swing.JComponent.processMouseEvent(JComponent.java:3324) 在java.awt.Component.processEvent(Component.java:6304) 在java.awt.Container.processEvent(Container.java:2239) 在java.awt.Component.dispatchEventImpl(Component.java:4889) 在java.awt.Container.dispatchEventImpl(Container.java:2297) 在java.awt.Component.dispatchEvent(Component.java:4711) 在java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4904) 在java.awt.LightweightDispatcher.processMouseEvent(Container.java:4535) 在java.awt.LightweightDispatcher.dispatchEvent(Container.java:4476) 在java.awt.Container.dispatchEventImpl(Container.java:2283) 在java.awt.Window.dispatchEventImpl(Window.java:2746) 在java.awt.Component.dispatchEvent(Component.java:4711) 在java.awt.EventQueue.dispatchEventImpl(EventQueue.java:760) 在java.awt.EventQueue.access $ 500(EventQueue.java:97) 在java.awt.EventQueue $ 3.run(EventQueue.java:709) 在java.awt.EventQueue $ 3.run(EventQueue.java:703) 在java.security.AccessController.doPrivileged(本机方法) 在java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74) 在java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:84) 在java.awt.EventQueue $ 4.run(EventQueue.java:733) 在java.awt.EventQueue $ 4.run(EventQueue.java:731) 在java.security.AccessController.doPrivileged(本机方法) 在java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74) 在java.awt.EventQueue.dispatchEvent(EventQueue.java:730) 在java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205) 在java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) 在java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) 在java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) 在java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) 在java.awt.EventDispatchThread.run(EventDispatchThread.java:82) 引起原因:org.apache.derby.client.am.SqlException:Spalten vom Typ'INTEGER'dürfenkeine Werte des Typs'CHAR'产生了兴趣。 在org.apache.derby.client.am.Statement.completeSqlca(未知来源) 在org.apache.derby.client.am.Statement.completeExecuteImmediate(未知来源) 在org.apache.derby.client.net.NetStatementReply.parseEXCSQLIMMreply(未知来源) 在org.apache.derby.client.net.NetStatementReply.readExecuteImmediate(未知来源) 在org.apache.derby.client.net.StatementReply.readExecuteImmediate(未知来源) 在org.apache.derby.client.net.NetStatement.readExecuteImmediate_(未知来源) 在org.apache.derby.client.am.Statement.readExecuteImmediate(未知来源) 在org.apache.derby.client.am.Statement.flowExecute(未知来源) 在org.apache.derby.client.am.Statement.executeX(未知来源) ...还有41个