Com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:You has an error in your SQL syntax; Che

Source: Internet
Author: User

I have encountered this error for a two of times.
1 The name of my field coincides with the keyword of the database.

Desc in is the default descending order of the meaning.
2 The second occurrence of the exception is a bug I encountered during the refactoring code phase. But I can't understand it for the time being, although it solves the mistake.
The code for the delete operation is as follows:

 Public void deleteproduct (Long id) {        = "DELETE from  t_product WHERE id=?" ;        JDBCTEMPLATE.TEMPLATEDML (Sql,id); }

Or the following wording: All is correct.

 Public void deleteproduct (Long id) {        = "DELETE from  t_product WHERE id=" +ID;        JDBCTEMPLATE.TEMPLATEDML (SQL);    }

But there is a problem when you query a result:

 Public Product Getproductbyid (Long ID) {        sql= "SELECT * from  t_product  WHERE id=?" ;        List<Product> list = jdbctemplate.templatedql (sql,id);         return list.size () ==1?list.get (0):null;    }

After the change can be again;

 Public Product Getproductbyid (Long ID) {        sql= "SELECT * from  t_product  WHERE id=" +ID;        List<Product> list = jdbctemplate.templatedql (sql);         return list.size () ==1?list.get (0):null;    }

Com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:You has an error in your SQL syntax; Che

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.