当我尝试在数据库中插入内容时,每个人都有问题。 DB方法是:
public static void insertInEntries(String NrDeOrdine, String NrDocument,String Data, String Emitent, String Continut, String Observatii)
throws SQLException {
Statement statement = (Statement) conn.createStatement();
try {
statement.executeUpdate("INSERT INTO Intrari " + "VALUES("
+ NrDeOrdine + "," + NrDocument + "," + Data + ","
+ Emitent + "," + Continut + "," + Observatii + ");");
System.out.println("Done");
} catch (SQLException e) {
System.err.println("Eroare:" + e);
}
}
在fxml中我有一个按钮,点击这个动作就可以了!
@FXML protected void eadaugareIn(ActionEvent event) throws SQLException {
DBConnection.connect();
DBConnection.getConnection();
try
{
DBConnection.insertInEntries(enrOrdInput.getText().toString(), enrDocInput.getText().toString(), edataInput.getText().toString(), eemitentInput.getText().toString(), econtinutTextArea.getText().toString(), eobsTextArea.getText().toString());
}
catch(SQLException e){
System.err.println("Eroare:" + e);
}
}
因此,如果在第一个文本字段中文本是“sa”我放入文本字段中,那么我在这个字段中放置的所有内容似乎都会出现错误:
Eroare:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'sa' in 'field list'
我怎么解决这个问题?非常感谢你!
编辑:几个小时前我找到了答案:statement.executeUpdate("INSERT INTO `intrari`(`NrDeOrdine`, `NrDocument`, `Data`, `Emitent`, `Continut`, `Observatii`)
VALUES("+ '"' + NrDeOrdine + '"' + "," + '"' + NrDocument + '"' + "," + '"'
+ Data + '"' + "," + '"' + Emitent + '"' + "," + '"' + Continut + '"' + ","
+ '"' + Observatii + '"' + ");");
答案 0 :(得分:0)
将记录添加到insertInEntries
方法:
System.out.println("INSERT INTO Intrari " + "VALUES("
+ NrDeOrdine + "," + NrDocument + "," + Data + ","
+ Emitent + "," + Continut + "," + Observatii + ");");
最有可能看到输出将为您提供解决方案。