Search code examples
javamysqldatabaseswingderby

java.sql.SQLSyntaxErrorException: Syntax error: Encountered "\',\'\',\'\',\'" at line 1, column 33


I am receiving an error when I tried to add quotation. I am trying to get a record from fields and then insert into derby database using Query. I'm getting an error that saying :java.sql.SQLSyntaxErrorException: Syntax error: Encountered "\',\'\',\'\',\'" at line 1, column 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();
                            }

Solution

  • Use this

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