2
我正在嘗試更新我的MS Access數據庫。我想知道爲什麼我得到的語法錯誤SQL異常錯誤
[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();
}
}
}
}
其他兩列中的兩個被命名爲'Order'和'Rate'。也包括這些名字。或者用表名或別名來限定他們。 – HansUp
我也把訂單和費率放在花括號裏。有效。 –
@TejalN將此答案標記爲正確,因爲我將工作評論插入答案中。 – HerrSerker