Several questions about JSP + MySql

Source: Internet
Author: User

Today, I am using JSP + MYSQL to create an object. The following error occurs: Java. SQL. sqlexception: Can not issue data manipulation statements with executequery ().

My intention is to execute the following statement:

Stmt = conn. createstatement ();
Stmt.exe cutequery (SQL );

To insert data, so we encountered the above problem and finally found the cause:

If your SQL statement is an update statement such as update and insert, you should use the execute () method of statement. If you use the executequery () method of statement, an appeal problem will occur. The reason is:

Resultset executequery (string SQL); throws sqlexception

Execute the given SQL statement, which returns a single resultset object. Parameter: SQL-the SQL statement to be sent to the database. It is usually returned by the static SQL SELECT statement: the resultset object that contains the data generated by the given query; it cannot be null. Throw: sqlexception-if a database access error occurs or a given
SQL statements generate any content other than a single resultset object. In short, the query statement uses executequery (SQL) and the update statement uses execute (). Therefore, you only need to change the code executequery (update_ SQL) to execute (update_ SQL.


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.