Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JAVA SQL命令未正确结束_Java_Oracle - Fatal编程技术网

JAVA SQL命令未正确结束

JAVA SQL命令未正确结束,java,oracle,Java,Oracle,我有以下代码: buy.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { int r; r = table.getSelectedRow(); String num = (String) table.getValueAt(r, 0);//numele jucarie

我有以下代码:

buy.addActionListener(new ActionListener()
{
    @Override
    public void actionPerformed(ActionEvent actionEvent)
    {
        int r;
        r = table.getSelectedRow();
        String num = (String) table.getValueAt(r, 0);//numele jucariei
        //String cop = (String) table.getValueAt(r, 3);//nr de bucati

        try
        {
            pq = stmt.executeQuery("SELECT *" + "FROM buyid_view");
            xv = stmt.executeQuery("SELECT toyid, copies " + "FROM alldatas_view" + "WHERE toyname ='"+num+"'");
            int buyid = pq.getInt("buyid");
            int toyid = xv.getInt("toyid");
            int copies = xv.getInt("copies");
            copies = copies-1;
            CallableStatement cstmt = con.prepareCall("INSERT INTO buy (buyid, toyid)" + "VALUES (?,?)");
            cstmt.setInt("buyid", buyid);
            cstmt.setInt("toyid", toyid);
            ResultSet rs = cstmt.executeQuery();
            JOptionPane.showMessageDialog(null, "You brought a toy.");

            for(int i = 0; i < table.getRowCount(); i++)
                for(int j = 0; j < table.getColumnCount(); j++)
                    table.setValueAt("", i, j);

            try
            {
                rs = stmt.executeQuery("UPDATE toys set copies "+ copies +"WHERE toyid= '"+toyid+"'");
            }
            catch (SQLException e)
            {
                JOptionPane.showMessageDialog(null, e.getMessage());
            }

            int i = 0;

            try
            {
                rs = stmt.executeQuery("SELECT *"+
                        "FROM availablebooks_view");
            }
            catch (SQLException e)
            {
                e.printStackTrace();
            }
            finally
            {
                try {
                    if(rs.next())
                    {
                        table.setValueAt(rs.getString(1), i, 0);
                        table.setValueAt(rs.getString(2), i, 1);
                        table.setValueAt(rs.getString(3), i, 2);
                        i++;
                        while(rs.next())
                        {
                            table.setValueAt(rs.getString(1), i, 0);
                            table.setValueAt(rs.getString(2), i, 1);
                            table.setValueAt(rs.getString(3), i, 2);
                            i++;
                        }
                    }
                } catch (SQLException e) {
                    JOptionPane.showMessageDialog(null, e.getMessage());
                }
            }
        }
        catch (SQLException e)
        {
            if(e.getMessage().contains("You have to pay!"))
                warning(frame, "You didn't pay all your products");
            else
                warning(frame, e.getMessage());
        }
    }
});

当我编译我的程序时,我没有任何错误,但当我运行它并单击“购买”按钮时,它会给我一个错误,说明ORA-00933:SQL命令未正确结束。

当从字符串生成SQL语句时,必须确保需要空格的地方有空格

rs = stmt.executeQuery("SELECT *"+
     "FROM availablebooks_view");
您发送的声明是

SELECT *FROM availablebooks_view
这是无效的语法。在代码中的几个地方都有这个问题


但是,您有一个更大的问题,这是由于零碎地构建SQL语句造成的。这使您可以重新编写代码,以使用准备好的语句和参数。

代码中存在多个错误

第一个是

rs = stmt.executeQuery("SELECT *"+
 "FROM availablebooks_view");
*和FROM之间没有空格,这实际上会产生语法错误

第二个是

rs = stmt.executeQuery("UPDATE toys set copies "+ copies +"WHERE toyid= '"+toyid+"'");
设置副本后没有=项,这也将创建错误

第三个是

CallableStatement cstmt = con.prepareCall("INSERT INTO buy (buyid, toyid)" + "VALUES (?,?)");

在值之前留出空格

哪个SQL语句需要正确结束?请编辑您的问题并删除所有其他代码,特别是Java部分,因为这是一条Oracle错误消息,而不是Java错误,因此只保留导致错误的SQL代码。提示:更新玩具集副本。。。是错误的,因为它缺少一个等号,它很容易SQL注入,它很难阅读等。