我在嘗試添加引號時收到錯誤。我試圖從字段中獲取記錄,然後使用Query插入到德比數據庫中。 我得到一個錯誤,說:java.sql.SQLSyntaxErrorException:語法錯誤:遇到 「\ '\ '\',\ '\',\'」 在1號線,列33java.sql.SQLSyntaxErrorException:語法錯誤:在第1行第33列遇到「','','','」
String Query = "select * from QUOTATION order by DATE DESC";
try {
Class.forName("org.apache.derby.jdbc.ClientDriver");
Connection conn = DriverManager.getConnection("jdbc:derby://localhost:1527/MavenUp","adminmu","admin");
Statement st= conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs=st.executeQuery(Query);
int id =0;
rs.beforeFirst();
if(rs.next())
{
id = rs.getInt(1);
id++;
}
else
{
id=1;
}
String idd = Integer.toString(id);
String Query1;
Query1 = "Insert into QUOTATION " + "values ("+idd+"','"+ClientName.getText()+"','"+QuotationNo.getText()+"','"+Date.getDate()+"'}";
if(st.executeUpdate(Query1)== 1)
{
JOptionPane.showMessageDialog(this,"Your Quote info has been Inserted");
}
else
{
JOptionPane.showMessageDialog(this, "Something went wrong Try again");
}
}catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch (SQLException e){
// TODO Auto-generated catch block
e.printStackTrace();
}
因爲你缺少單引號 –
1.調試工具_方式_在這些類型的問題的更有用比我們什麼您正在執行的查詢是錯誤的。 2.請不要使用字符串連接來構建查詢 - JDBC具有綁定參數的概念,這對於查詢非常有用。 –
然後我應該怎樣,否則字符串連接 – Sparta