2017-08-15 1 views
0

Ich versuche Zeilen Daten aus JTable Tabelle in SQL-Datenbank einzufügen, sondern auf LaufzeitLegen Sie mehr Zeilen aus jtable auf SQL-Datenbanktabelle

falsche Syntax nahe dem Schlüsselwort ‚Transaktion‘ Fehler auftritt.

Hier ist der Code

try { 

    int rows = table.getRowCount(); 

    // con.setAutoCommit(false); 
    String query = "Insert into Transaction(transaction_code, transaction_date, item_code, item_name, quantity, item_price, total) values (?,?,?,?,?,?,?) ;"; 
    PreparedStatement pst = con.prepareStatement(query); 
    for (int row = 0; row < rows; row++) { 
     int t_code = (int) table.getValueAt(row, 0); 
     Timestamp t_date = (Timestamp) table.getValueAt(row, 1); 
     int i_code = (int) table.getValueAt(row, 2); 
     String i_name = (String) table.getValueAt(row, 3); 
     int quantity = (int) table.getValueAt(row, 4); 
     BigDecimal i_price = (BigDecimal) table.getValueAt(row, 5); 
     BigDecimal total = (BigDecimal) table.getValueAt(row, 6); 
     pst.setInt(1, t_code); 
     pst.setTimestamp(2, t_date); 
     pst.setInt(3, i_code); 
     pst.setString(4, i_name); 
     pst.setInt(5, quantity); 
     pst.setBigDecimal(6, i_price); 
     pst.setBigDecimal(7, total); 

     pst.addBatch(); 
    } 
    pst.executeBatch(); 
    pst.execute(query); 
    //con.commit(); 
} catch (Exception e1) { 
    e1.printStackTrace(); 

} 
+0

Transaktion ist reservierte Wort –

+0

Das Wort "Transaktion" ist ein reserviertes Wort in den meisten SQL-Datenbank, müssen Sie es wie "Transaction" nennen ... –

+0

wwhat DBMS, das du benutzt? –

Antwort

0

Transaction ein keyword in mysql ist ein viele andere dbms. Verwenden Sie es nicht als Tabellenname oder entkommen Sie es mit Backticks

Verwandte Themen