Kaveri Patel
Kaveri Patel

Reputation: 27

error in java update

   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;
    }

and i got error as:

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.

please help me...

Upvotes: 0

Views: 93

Answers (1)

Iswanto San
Iswanto San

Reputation: 18569

Since DESC is a keyword, you must surround it with [].

Use this for your query:

 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()
                    + "'";

Upvotes: 1

Related Questions