java.sql.SQLSyntaxErrorException:语法错误:在第1行第33列遇到“\”,\'\',\'\',\'“

时间:2017-04-09 13:59:16

标签: java mysql database swing derby

我在尝试添加引号时收到错误。我试图从字段中获取记录,然后使用Query插入到derby数据库中。    我收到的错误是:java.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 个答案:

答案 0 :(得分:1)

使用此

Query1 = "Insert into QUOTATION " + "values  ('"+idd+"','"+ClientName.getText()+"','"+QuotationNo.getText()+"','"+Date.getDate()+"')";
相关问题