Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.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_Ms Access_Jdbc Odbc - Fatal编程技术网

Java SQL异常错误

Java SQL异常错误,java,ms-access,jdbc-odbc,Java,Ms Access,Jdbc Odbc,我正在尝试更新我的MS Access数据库。我想知道为什么会出现语法错误 [java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in UPDATE statement.] 即使语法正确 class modify implements ActionListener { public void actionPerformed(ActionEvent ae) {

我正在尝试更新我的MS Access数据库。我想知道为什么会出现语法错误

[java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in 
UPDATE statement.] 
即使语法正确

class modify implements ActionListener
{
    public void actionPerformed(ActionEvent ae)
    {
        try{

            Integer num1=Integer.parseInt(tfdid.getText());
            if(num1.equals(null))
            {
                System.out.println("num");
                throw new BlankException();
            }


            String name1=tfname.getText();
            int a;
             a=name1.charAt(0);
            if(name1.equals("") || a==32)
                {
                    throw new BlankException();
                }
            else
            {
                for(int i=0; i<name1.length(); i++)
                {
                    boolean check = Character.isLetter(name1.charAt(i));
                    a=name1.charAt(i);
                    System.out.print("  "+a);
                    if(!((a>=65 && a<=90) || (a>=97 && a<=122) || (a==32) ||(a==46)))
                    {
                      throw new NameEx();
                    }

                }
            }


            String addr1=taadd.getText();
            if(addr1.equals(null))
            {
                System.out.println("addr");
                throw new BlankException();
            }

            String contact1=tftel.getText();
            String fax=tfax.getText();
            String dateorder=tfdateadd.getText();
            String dod=tfdod.getText();
            String order=taorder.getText();
            String rate = tfrate.getText();
            String quantity = tfquantity.getText();
            String paytype=chrt.getSelectedItem();
            String itemcode=tfitemcode.getText();

            String discount=tdiscount.getText();
            if(discount.equals(null))
            {
                System.out.println("discount");
                throw new BlankException();
            }

                System.out.println("NUm="+num1);            
                System.out.println("name="+name1);          
                System.out.println("addr="+addr1);      
                System.out.println("contact="+contact1);        
                System.out.println("fax="+fax); 
                System.out.println("orderdate="+dateorder); 
                System.out.println("dod="+dod);     
                System.out.println("order="+order);             
                System.out.println("rate="+rate);               
                System.out.println("quantity="+quantity);               
                System.out.println("pay="+paytype);
                System.out.println("itemcode="+itemcode);
                System.out.println("discount="+discount);

            //Statement st1=cn.createStatement();   

            String str="UPDATE DOC SET Name=?,Address=?,Contact=?,Fax=?,Order_date=?,Delivery_date=?,Order=?,Rate=?,Quantity=?,
            Payment_method=?,Item_code=?,Discount=? WHERE Vendorid=?";
            Statement st1= cn.createStatement();

            PreparedStatement psmt=cn.prepareStatement(str);

            psmt.setString(1,name1);
            psmt.setString(2,addr1);
            psmt.setString(3,contact1);
            psmt.setString(4,fax);
            psmt.setString(5,dateorder);
            psmt.setString(6,dod);
            psmt.setString(7,order);
            psmt.setString(8,rate);
            psmt.setString(9,quantity);
            psmt.setString(10,paytype);
            psmt.setString(11,itemcode);
            psmt.setString(12,discount);
                psmt.setInt(13,num1);


            psmt.executeUpdate();

            new SuccessDialog2();


            }catch(SQLException sq)
        {
            String message = "Enter Valid Vendor ID and Contact.";
            JOptionPane.showMessageDialog(new JFrame(), message, "ERROR!",
            JOptionPane.ERROR_MESSAGE);
            System.out.println(sq);
        }
        catch(BlankException be)
        {
            new ErrorDialog2();
        }
        catch(NumberFormatException nfe)
        {
            new ErrorDialog();
        }
        catch(NameEx ne)
        {
            new ErrorDialog1();
        }
        catch(Exception e)
        {
            System.out.println(e);
            new EDt();
        }

    }
}   
}
类修改实现ActionListener
{
已执行的公共无效行动(行动事件ae)
{
试一试{
整数num1=Integer.parseInt(tfdid.getText());
如果(num1等于(空))
{
System.out.println(“num”);
抛出新的BlankException();
}
字符串名称1=tfname.getText();
INTA;
a=名称1.字符(0);
如果(名称1.equals(“”| | a==32)
{
抛出新的BlankException();
}
其他的
{

对于(int i=0;i=65&&a=97&&a是否确定数据库中的所有值都是
String
值?如果不是,则需要使用
setInt()
setLong()
等:)


您的
数量
有一个
字符串
值,这似乎有点奇怪。

名称
是Access SQL中的保留字,因此如果它被用作列名,则必须将其括在方括号中,例如

String str=“更新单据集[名称]=。。。

ORDER
RATE
也是如此。因此也将这两个列括起来。

其他两列分别命名为
ORDER
RATE
。也将这些名称括起来。或者用表名或别名对它们进行限定。@TejalN在答案中插入工作注释时,将此答案标记为正确。