0
   if (e.getSource() == btn_updt) {
        try {

            String str = "img";

            int max_avail;

            double price;

            Frame f = new Frame();

            Connection con;

            DriverManager
                    .registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver());

            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

            con = DriverManager.getConnection("jdbc:odbc:dsnproj", "", "");

            Statement s = con.createStatement();

            // int mno=Integer.parseInt(txt_contcno.getText());

            price = Double.parseDouble(txt_price.getText());

            max_avail = Integer.parseInt(txt_qty_avl.getText());

            String qry_up = "update category set prod_name='"
                    + txt_pro_nm.getText() + "',desc='"
                    + txt_pro_desc.getText() + "',photo='" + str
                    + "',max_quan_avail=" + max_avail + ",cur_price="
                    + price + ",per='" + ch_weight.getSelectedItem()
                    + "' where   p_name='" + ch_pro_nm.getSelectedItem()
                    + "'";

            System.out.println(qry_up);

            s.execute(qry_up);

            System.out.println("updated");

            // JOptionPane.showMessageDialog(f,
            // "Updates Successfully : ","A plain message",JOptionPane.PLAIN_MESSAGE);
        } catch (Exception ae) {
            System.out.println(ae.getLocalizedMessage());
        }

        return result;
    }

我得到了错误:

update category set prod_name='jjhhj',desc='jjjh',photo='img',max_quan_avail=88,cur_price=99.0,per='piece' where p_name='brush' [Microsoft][ODBC Microsoft Access Driver] Syntax error in UPDATE statement.

请帮我...

4

1 回答 1

1

由于DESC是关键字,因此必须用[].

将此用于您的查询:

 String qry_up = "update category set prod_name='"
                    + txt_pro_nm.getText() + "',[desc]='"
                    + txt_pro_desc.getText() + "',photo='" + str
                    + "',max_quan_avail=" + max_avail + ",cur_price="
                    + price + ",per='" + ch_weight.getSelectedItem()
                    + "' where   p_name='" + ch_pro_nm.getSelectedItem()
                    + "'";
于 2013-03-03T10:51:10.090 回答