2017-04-09 130 views
0

我在尝试添加引号时收到错误。我试图从字段中获取记录,然后使用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(); 
          } 
+0

因为你缺少单引号 –

+0

1.调试工具_方式_在这些类型的问题的更有用比我们什么您正在执行的查询是错误的。 2.请不要使用字符串连接来构建查询 - JDBC具有绑定参数的概念,这对于查询非常有用。 –

+0

然后我应该怎样,否则字符串连接 – Sparta

回答

1

使用此

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

现在它给出这个错误 java.sql.SQLSyntaxErrorException:语法错误:在第1行第78列遇到“}” – Sparta

+0

我已经更新了我的答案。 ü只需要删除'}' –

+0

啊,是工作,但现在它给这个 java.sql.SQLSyntaxErrorException:第1行,列77 – Sparta

相关问题