Can Not Issue Data Manipulation Statements With Executequery | How To Mysql : Cannot Issue Data Manipulation Statements With Executequery() 인기 답변 업데이트

당신은 주제를 찾고 있습니까 “can not issue data manipulation statements with executequery – How to MySQL : Cannot issue data manipulation statements with executeQuery()“? 다음 카테고리의 웹사이트 Chewathai27.com/you 에서 귀하의 모든 질문에 답변해 드립니다: Chewathai27.com/you/blog. 바로 아래에서 답을 찾을 수 있습니다. 작성자 Solutions Cloud 이(가) 작성한 기사에는 조회수 4회 및 좋아요 없음 개의 좋아요가 있습니다.

Table of Contents

can not issue data manipulation statements with executequery 주제에 대한 동영상 보기

여기에서 이 주제에 대한 비디오를 시청하십시오. 주의 깊게 살펴보고 읽고 있는 내용에 대한 피드백을 제공하세요!

d여기에서 How to MySQL : Cannot issue data manipulation statements with executeQuery() – can not issue data manipulation statements with executequery 주제에 대한 세부정보를 참조하세요

How to MySQL : Cannot issue data manipulation statements with executeQuery() \r
[ Ext for Developers : https://www.hows.tech/p/recommended.html ] \r
\r
How to MySQL : Cannot issue data manipulation statements with executeQuery() \r
\r
Note: The information provided in this video is as it is with no modifications.\r
Thanks to many people who made this project happen. Disclaimer: All information is provided as it is with no warranty of any kind. Content is licensed under CC BY SA 2.5 and CC BY SA 3.0. Question / answer owners are mentioned in the video. Trademarks are property of respective owners and stackexchange. Information credits to stackoverflow, stackexchange network and user contributions. If there any issues, contact us on – solved dot hows dot tech\r
\r
#HowtoMySQL:CannotissuedatamanipulationstatementswithexecuteQuery() #How #to #MySQL #: #Cannot #issue #data #manipulation #statements #with #executeQuery()\r
\r
Guide : [ How to MySQL : Cannot issue data manipulation statements with executeQuery() ] Disclaimer: This video is just for educational purpose. The video demonstrates the study of the program and code shown.

can not issue data manipulation statements with executequery 주제에 대한 자세한 내용은 여기를 참조하세요.

Cannot issue data manipulation statements with executeQuery()

To manipulate data you actually need executeUpdate() rather than executeQuery() . Here’s an extract from the executeUpdate() javadoc which …

+ 여기에 더 보기

Source: stackoverflow.com

Date Published: 2/25/2021

View: 2634

Can not issue data manipulation statements with executeQuery

I’m getting an error when im trying to run my gui to inset data into a table, the error being Can not issue data manipulation statements with executeQuery() …

+ 여기에 보기

Source: java.tutorialink.com

Date Published: 12/8/2022

View: 7627

java.sql.SQLException: Can not issue data manipulation …

SQLException: Can not issue data manipulation statements with executeQuery(). Recently while trying to delete specific rows from a table …

+ 자세한 내용은 여기를 클릭하십시오

Source: anshulgnit.blogspot.com

Date Published: 10/2/2021

View: 3301

Spring Jpa Update Can Not Issue Data Manipulation …

SQLException: Can not issue data manipulation statements with executeQuery(). @Modifing @Transactional @Query(value = “DELETE FROM PHOTO AS p WHERE p.USER_ID …

+ 여기에 자세히 보기

Source: www.faqcode4u.com

Date Published: 9/17/2022

View: 543

Cannot issue data manipulation statements with executeQuery()

To manipulate data you actually need executeUpdate() rather than executeQuery(). Here’s an extract from the executeUpdate() javadoc which is …

+ 여기에 더 보기

Source: www.configrouter.com

Date Published: 10/8/2021

View: 6325

Can not issue data manipulation statements with executeQuery()

java – Can not issue data manipulation statements with executeQuery(). You will need to use the executeUpdate() method to execute the INSERT …

+ 더 읽기

Source: technoteshelp.com

Date Published: 4/28/2021

View: 993

java.sql.SQLException: Can not issue data … – actorsfit

java.sql.SQLException: Can not issue data manipulation statements with executeQuery(). at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:996) at …

+ 여기를 클릭

Source: blog.actorsfit.com

Date Published: 5/21/2021

View: 3421

SQLException: “Can not issue data manipulation statements …

Instead of: stmt.executeQuery(queryAccount);. use: stmt.executeUpdate(queryAccount);.

+ 더 읽기

Source: helpex.vn

Date Published: 2/14/2022

View: 3376

Cannot issue data manipulation statements with executequery()

To have as few implementation dependencies as feasible, Java is an object-oriented programming … I will welcome your feedback and …

+ 더 읽기

Source: kodlogs.net

Date Published: 6/16/2022

View: 7893

주제와 관련된 이미지 can not issue data manipulation statements with executequery

주제와 관련된 더 많은 사진을 참조하십시오 How to MySQL : Cannot issue data manipulation statements with executeQuery(). 댓글에서 더 많은 관련 이미지를 보거나 필요한 경우 더 많은 관련 기사를 볼 수 있습니다.

How to MySQL : Cannot issue data manipulation statements with executeQuery()
How to MySQL : Cannot issue data manipulation statements with executeQuery()

주제에 대한 기사 평가 can not issue data manipulation statements with executequery

  • Author: Solutions Cloud
  • Views: 조회수 4회
  • Likes: 좋아요 없음
  • Date Published: 2022. 4. 30.
  • Video Url link: https://www.youtube.com/watch?v=yQvNpN2uTEQ

What executeQuery () method will after executing the statement?

executeQuery : Returns one ResultSet object. executeUpdate : Returns an integer representing the number of rows affected by the SQL statement. Use this method if you are using INSERT , DELETE , or UPDATE SQL statements.

What is executeQuery ()?

executeQuery() : This method is used to retrieve data from database using SELECT query. This method returns the ResultSet object that returns the data according to the query. Follow this answer to receive notifications.

What type of value is returned by the executeQuery ()?

Output. executeQuery(): This method is used to execute statements that returns tabular data (example select). It returns an object of the class ResultSet.

What is executeUpdate in Java?

This executeUpdate method is specified by the executeUpdate method in the java. sql. Statement interface. If executing a stored procedure results in an update count that is greater than one, or that generates more than one result set, use the execute method to execute the stored procedure.

What is the difference between execute and executeQuery?

execute method can run both select and insert/update statements. executeQuery method execute statements that returns a result set by fetching some data from the database. It executes only select statements. executeUpdate method execute sql statements that insert/update/delete data at the database.

What are the types of JDBC architecture explain them explain the difference between execute executeQuery and executeUpdate?

Statement interface of JDBC which are used to execute SQL statements. executeQuery() command used for getting the data from database whereas executeUpdate() command used for insert,update,delete or execute() command used forany kind of operations.

Can we use executeQuery for update?

SQLException with message “executeQuery method can not be used for update”. Statement executeUpdate(String query) is used to execute Insert/Update/Delete (DML) statements or DDL statements that returns nothing.

What is the difference between ExecuteScalar and ExecuteNonQuery?

Solution 1. ExecuteScalar() only returns the value from the first column of the first row of your query. ExecuteReader() returns an object that can iterate over the entire result set. ExecuteNonQuery() does not return data at all: only the number of rows affected by an insert, update, or delete.

What is the difference between Statement PreparedStatement and CallableStatement?

It is used when you want to use the database stored procedures. CallableStatement can accept runtime input parameters.

Difference between CallableStatement and PreparedStatement :
CallableStatement PreparedStatement
Performance is very high. Performance is better than Statement.
22 thg 7, 2020

Which methods are not in Statement interface?

The Statement interface cannot accept parameters. PreparedStatement: It represents the pre-compiled SQL statements that can be executed multiple times. CallableStatement: It is used to execute SQL stored procedures. QueryStatement: It is not supported by JDBC.

Which of the following method is supported by Statement interface?

The important methods of Statement interface are as follows: 1) public ResultSet executeQuery(String sql): is used to execute SELECT query. It returns the object of ResultSet. 2) public int executeUpdate(String sql): is used to execute specified query, it may be create, drop, insert, update, delete etc.

What is the return type of STMT executeQuery () method where STMT is Statement object?

In the try block, the Statement object is created and stored in stmt using the Connection object’s createdStatement( ) method. Then, the Statement object’s executeQuery( ) method is called to execute the SQL SELECT statement, returning a ResultSet into rset .

What does executeUpdate () method of query interface returns?

The executeUpdate() method returns the number of rows affected by the SQL statement (an INSERT typically affects one row, but an UPDATE or DELETE statement can affect more).

What does executeUpdate return in JDBC?

The JDBC standard states that the executeUpdate method returns a row count or 0. However, if the executeUpdate method is executed against a Db2 for z/OS server, it can return a value of -1.

What is the difference between Statement and PreparedStatement?

Statement will be used for executing static SQL statements and it can’t accept input parameters. PreparedStatement will be used for executing SQL statements many times dynamically. It will accept input parameters.

Which method is used to execute DDL statements?

Executing DDL (Data Definition Language) Queries

execute() method. You get an instance of this class by calling the createStatement method of your connection object.

Which method is used to execute SQL SELECT Statement and returns a result?

The “execute” method executes a SQL statement and indicates the form of the first result. You can then use getResultSet or getUpdateCount to retrieve the result, and getMoreResults to move to any subsequent result(s). getResultSet returns the current result as a ResultSet.

Which method will return boolean When we try to execute SQL query from a JDBC program?

boolean execute(String SQL) : Returns a boolean value of true if a ResultSet object can be retrieved; otherwise, it returns false. Use this method to execute SQL DDL statements or when you need to use the truly dynamic SQL.

Which of the following method can be used to execute to execute all type of queries ie either selection or Updation SQL queries?

The executeQuery() method of Statement interface is used to execute queries to the database. This method returns the object of ResultSet that can be used to get all the records of a table.

Cannot issue data manipulation statements with executeQuery()

In MySQL I have two tables, tableA and tableB . I am trying to execute two queries:

executeQuery(query1) executeQuery(query2)

But I get the following error:

can not issue data manipulation statements with executeQuery().

What does this mean?

Can not issue data manipulation statements with executeQuery

I’m getting an error when im trying to run my gui to inset data into a table, the error being Can not issue data manipulation statements with executeQuery(). The goal of this gui is to get the user to input information into the text area and then click submit and this information is uploaded to the database.

error : java.sql.SQLException: Can not issue data manipulation statements with executeQuery().

Answer

You have to use this method PreparedStatement#executeUpdate() instead of executeQuery

Processing SQL Statements with JDBC (The Java™ Tutorials > JDBC Database Access > JDBC Basics)

Trail: JDBC Database Access

Lesson: JDBC Basics

The Java Tutorials have been written for JDK 8. Examples and practices described in this page don’t take advantage of improvements introduced in later releases and might use technology no longer available. See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases. See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.

Processing SQL Statements with JDBC

In general, to process any SQL statement with JDBC, you follow these steps:

This page uses the following method, CoffeesTable.viewTable , from the tutorial sample to demonstrate these steps. This method outputs the contents of the table COFFEES . This method will be discussed in more detail later in this tutorial:

public static void viewTable(Connection con) throws SQLException { String query = “select COF_NAME, SUP_ID, PRICE, SALES, TOTAL from COFFEES”; try (Statement stmt = con.createStatement()) { ResultSet rs = stmt.executeQuery(query); while (rs.next()) { String coffeeName = rs.getString(“COF_NAME”); int supplierID = rs.getInt(“SUP_ID”); float price = rs.getFloat(“PRICE”); int sales = rs.getInt(“SALES”); int total = rs.getInt(“TOTAL”); System.out.println(coffeeName + “, ” + supplierID + “, ” + price + “, ” + sales + “, ” + total); } } catch (SQLException e) { JDBCTutorialUtilities.printSQLException(e); } }

First, establish a connection with the data source you want to use. A data source can be a DBMS, a legacy file system, or some other source of data with a corresponding JDBC driver. This connection is represented by a Connection object. See Establishing a Connection for more information.

A Statement is an interface that represents a SQL statement. You execute Statement objects, and they generate ResultSet objects, which is a table of data representing a database result set. You need a Connection object to create a Statement object.

For example, CoffeesTable.viewTable creates a Statement object with the following code:

stmt = con.createStatement();

There are three different kinds of statements:

Statement : Used to implement simple SQL statements with no parameters.

: Used to implement simple SQL statements with no parameters. PreparedStatement : (Extends Statement .) Used for precompiling SQL statements that might contain input parameters. See Using Prepared Statements for more information.

: (Extends .) Used for precompiling SQL statements that might contain input parameters. See Using Prepared Statements for more information. CallableStatement: (Extends PreparedStatement .) Used to execute stored procedures that may contain both input and output parameters. See Stored Procedures for more information.

To execute a query, call an execute method from Statement such as the following:

execute : Returns true if the first object that the query returns is a ResultSet object. Use this method if the query could return one or more ResultSet objects. Retrieve the ResultSet objects returned from the query by repeatedly calling Statement.getResultSet .

: Returns if the first object that the query returns is a object. Use this method if the query could return one or more objects. Retrieve the objects returned from the query by repeatedly calling . executeQuery : Returns one ResultSet object.

: Returns one object. executeUpdate : Returns an integer representing the number of rows affected by the SQL statement. Use this method if you are using INSERT , DELETE , or UPDATE SQL statements.

For example, CoffeesTable.viewTable executed a Statement object with the following code:

ResultSet rs = stmt.executeQuery(query);

See Retrieving and Modifying Values from Result Sets for more information.

You access the data in a ResultSet object through a cursor. Note that this cursor is not a database cursor. This cursor is a pointer that points to one row of data in the ResultSet object. Initially, the cursor is positioned before the first row. You call various methods defined in the ResultSet object to move the cursor.

For example, CoffeesTable.viewTable repeatedly calls the method ResultSet.next to move the cursor forward by one row. Every time it calls next , the method outputs the data in the row where the cursor is currently positioned:

ResultSet rs = stmt.executeQuery(query); while (rs.next()) { String coffeeName = rs.getString(“COF_NAME”); int supplierID = rs.getInt(“SUP_ID”); float price = rs.getFloat(“PRICE”); int sales = rs.getInt(“SALES”); int total = rs.getInt(“TOTAL”); System.out.println(coffeeName + “, ” + supplierID + “, ” + price + “, ” + sales + “, ” + total); } // …

See Retrieving and Modifying Values from Result Sets for more information.

When you are finished using a Connection , Statement , or ResultSet object, call its close method to immediately release the resources it’s using.

Alternatively, use a try -with-resources statement to automatically close Connection , Statement , and ResultSet objects, regardless of whether an SQLException has been thrown. (JDBC throws an SQLException when it encounters an error during an interaction with a data source. See Handling SQL Exceptions for more information.) An automatic resource statement consists of a try statement and one or more declared resources. For example, the CoffeesTable.viewTable method automatically closes its Statement object, as follows:

public static void viewTable(Connection con) throws SQLException { String query = “select COF_NAME, SUP_ID, PRICE, SALES, TOTAL from COFFEES”; try (Statement stmt = con.createStatement()) { ResultSet rs = stmt.executeQuery(query); while (rs.next()) { String coffeeName = rs.getString(“COF_NAME”); int supplierID = rs.getInt(“SUP_ID”); float price = rs.getFloat(“PRICE”); int sales = rs.getInt(“SALES”); int total = rs.getInt(“TOTAL”); System.out.println(coffeeName + “, ” + supplierID + “, ” + price + “, ” + sales + “, ” + total); } } catch (SQLException e) { JDBCTutorialUtilities.printSQLException(e); } }

The following statement is a try -with-resources statement, which declares one resource, stmt , that will be automatically closed when the try block terminates:

try (Statement stmt = con.createStatement()) { // … }

Statement.execute(sql) vs executeUpdate(sql) and executeQuery(sql)

I have a question related to this method: st.execute(sql); where st obviously is a Statement object. Directly from this oracle java tutorial:

execute: Returns true if the first object that the query returns is a ResultSet object. Use this method if the query could return one or more ResultSet objects. Retrieve the ResultSet objects returned from the query by repeatedly calling Statement.getResutSet.

What is meant by “one or more ResultSet objects”? How is it possible to manage them once got an array of ResultSet ? Whereas st.executeQuery(sql) and st.executeUpdate(sql) are very clear. It’s not (at least to me) the aim of st.execute(sql) which can also return an int as if it was updated a table.

Thanks in advance

What is the difference between execute(), executeQuery() and executeUpdate() methods in JDBC?

What is the difference between execute(), executeQuery() and executeUpdate() methods in JDBC?

Once you have created the statement object you can execute it using one of the execute methods of the Statement interface namely, execute(), executeUpdate() and, executeQuery().

The execute() method: This method is used to execute SQL DDL statements, it returns a boolean value specifying weather the ResultSet object can be retrieved.

Example

import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; public class Example { public static void main(String args[]) throws SQLException { //Registering the Driver DriverManager.registerDriver(new com.mysql.jdbc.Driver()); //Getting the connection String mysqlUrl = “jdbc:mysql://localhost/sampleDB”; Connection con = DriverManager.getConnection(mysqlUrl, “root”, “password”); System.out.println(“Connection established……”); //Creating the Statement Statement stmt = con.createStatement(); //Executing the statement String createTable = “CREATE TABLE Employee( ” + “Name VARCHAR(255), ” + “Salary INT NOT NULL, ” + “Location VARCHAR(255))”; boolean bool = stmt.execute(createTable); System.out.println(bool); } }

Output

Connection established…… false

executeUpdate(): This method is used to execute statements such as insert, update, delete. It returns an integer value representing the number of rows affected.

Example

import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; public class ExecuteUpdateExample { public static void main(String args[]) throws SQLException { //Registering the Driver DriverManager.registerDriver(new com.mysql.jdbc.Driver()); //Getting the connection String mysqlUrl = “jdbc:mysql://localhost/sampleDB”; Connection con = DriverManager.getConnection(mysqlUrl, “root”, “password”); System.out.println(“Connection established……”); //Creating the Statement Statement stmt = con.createStatement(); String insertData = “INSERT INTO Employee(” + “Name, Salary, Location) VALUES ” + “(‘Amit’, 30000, ‘Hyderabad’), ” + “(‘Kalyan’, 40000, ‘Vishakhapatnam’), ” + “(‘Renuka’, 50000, ‘Delhi’), ” + “(‘Archana’, 15000, ‘Mumbai’)”; int i = stmt.executeUpdate(insertData); System.out.println(“Rows inserted: “+i); } }

Output

Connection established…… Rows inserted: 4

executeQuery(): This method is used to execute statements that returns tabular data (example select). It returns an object of the class ResultSet.

Example

import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class ExecuteQueryExample { public static void main(String args[]) throws SQLException { //Registering the Driver DriverManager.registerDriver(new com.mysql.jdbc.Driver()); //Getting the connection String mysqlUrl = “jdbc:mysql://localhost/sampleDB”; Connection con = DriverManager.getConnection(mysqlUrl, “root”, “password”); System.out.println(“Connection established……”); //Creating the Statement Statement stmt = con.createStatement(); //Retrieving data ResultSet rs = stmt.executeQuery(“Select *from Employee”); while(rs.next()) { System.out.print(“Name: “+rs.getString(“Name”)+”, “); System.out.print(“Salary: “+rs.getInt(“Salary”)+”, “); System.out.print(“City: “+rs.getString(“Location”)); System.out.println(); } } }

Output

Connection established…… Name: Amit, Salary: 30000, City: Hyderabad Name: Kalyan, Salary: 40000, City: Vishakhapatnam Name: Renuka, Salary: 50000, City: Delhi Name: Archana, Salary: 15000, City: Mumbai

executeUpdate Method (java.lang.String) (SQLServerStatement) – JDBC Driver for SQL Server

Table of contents

Article

11/02/2021

2 minutes to read

4 contributors

In this article

Download JDBC Driver

Runs the given SQL statement, which can be an INSERT, UPDATE, or DELETE statement; or an SQL statement that returns nothing, such as an SQL DDL statement. Beginning in MicrosoftSQL Server JDBC Driver 3.0, executeUpdate will return the correct number of rows updated in a MERGE operation.

Syntax

public int executeUpdate(java.lang.String sql)

Parameters

sql

A String that contains the SQL statement.

Return Value

An int that indicates the number of rows affected, or 0 if using a DDL statement.

Exceptions

SQLServerException

Remarks

This executeUpdate method is specified by the executeUpdate method in the java.sql.Statement interface.

If executing a stored procedure results in an update count that is greater than one, or that generates more than one result set, use the execute method to execute the stored procedure.

See Also

executeUpdate Method (SQLServerStatement)

SQLServerStatement Members

SQLServerStatement Class

Spring Jpa Update Can Not Issue Data Manipulation Statements With Executequery

Tags: java , spring , mysql , spring-jdbc Answers: 1 | Viewed 8,782 times

I try to use handle query for updating table in the SQL database.

Code:

@Autowired

private ProducerRepository producerRepository;

public void update(Producer producer){

String name = producer.getProducerName();

long id = producer.getId();

// producerRepository.save(producer); //this method works well.

producerRepository.update(name, id); //handle attempt – throws exeption in this string

}

ProducerRepository:

@Repository

public interface ProducerRepository extends JpaRepository{

@Query(nativeQuery = true, value = “UPDATE producer SET producer_name = :pName WHERE id = :id”)

Producer update(

@Param(“pName”) String pName,

@Param(“id”) long id

);

}

All parameters of the producer entity are correct and producerRepository.save(producer) works well.

(also I out in console name and id fields – all right)

So, I can save producer in the database, but, when I try to use update() method I get the error.

Can not issue data manipulation statements with executeQuery()

PS

sql query in the console also works well

(UPDATE producer SET producer_name = ‘some name’ WHERE id = ….)

It should be noted that other SQL native queries in repository work correctly. So the spring/hibernate/jdbc settings are correct.

Cannot issue data manipulation statements with executeQuery()

To manipulate data you actually need executeUpdate() rather than executeQuery().

Here’s an extract from the executeUpdate() javadoc which is already an answer at its own:

Executes the given SQL statement, which may be an INSERT, UPDATE, or DELETE statement or an SQL statement that returns nothing, such as an SQL DDL statement.

When executing DML statement , you should use executeUpdate/execute rather than executeQuery.

Here is a brief comparison :

java – Can not issue data manipulation statements with executeQuery() – Tech Notes Help

java – Can not issue data manipulation statements with executeQuery()

You will need to use the executeUpdate() method to execute the INSERT statement, while youll need to use the executeQuery() method to execute the SELECT statement. This is due to the requirements imposed by the JDBC specification on their usages:

From the Java API documentation for Statement.executeQuery():

Executes the given SQL statement, which returns a single ResultSet

object. Parameters: sql – an SQL statement to be sent to the database, typically a static SQL SELECT statement

and from the Java API documentation for Statement.executeUpdate():

Executes the given SQL statement, which may be an INSERT, UPDATE, or DELETE statement or an SQL statement that returns nothing, such as an SQL DDL statement. Parameters: sql – an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement.

Your code (pseudo-code posted here) should appear as:

statement.executeUpdate(INSERT INTO Sessions(id_user) VALUES(1)); // DML operation statement.executeQuery(SELECT LAST_INSERT_ID()); // SELECT operation

And of course, the MySQL documentation demonstrates how to perform the same activity for AUTO_INCREMENT columns, which is apparently what you need.

If you need to execute both of them together in the same transaction, by submitting the statements in one string with a semi-colon separating them like the following:

statement.execute(INSERT INTO Sessions(id_user) VALUES(1); SELECT LAST_INSERT_ID() FROM Sessions LIMIT 1;);

then youll need to use the execute() method. Note, that this depends on the support offered by the Database and the JDBC driver for batching statements together in a single execute(). This is supported in Sybase and MSSQL Server, but I do not think it is supported in MySQL.

may be you are using executeQuery() but to manipulate data you actually need executeUpdate() rather than executeQuery()

java – Can not issue data manipulation statements with executeQuery()

java.sql.SQLException: Can not issue data manipulation statements with executeQuery().

1. Error description

java.sql.SQLException: Can not issue data manipulation statements with executeQuery(). at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:996) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:935) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:924) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:870) at com.mysql.jdbc.StatementImpl.checkForDml(StatementImpl.java:472) at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1401) at com.you.sql.Student.commonMethod(Student.java:117) at com.you.sql.Student.insertStudent(Student.java:86) at com.you.sql.Student.main(Student.java:181)

2. Reason of error

public static void insertStudent() { StringBuffer sql = new StringBuffer(); int j = 0; String str = “0”; for(int i=5;i<1000;i++) { ++j; if(i%2 == 0) { str = "0"; } else { str = "1"; } sql.append("insert into t_stu_info (").append(i).append(",").append(103+j+"").append(",") .append("zhangsan"+(i-4)).append(",").append(str).append(",") .append(Integer.parseInt(Math.round(Math.random()*10+20)+"")).append(",") .append("123"+i); } commonMethod(sql.toString()); } /** * * @Title:Student * @Description: * @param sqlStu * @Date: 12:25:56 AM, June 11, 2015 * @return :void * @throws */ public static void commonMethod(String sqlStu) { StringBuffer sql = new StringBuffer(); sql.append(sqlStu); Connection conn = null; Statement stat = null; ResultSet rs = null; try { try { Class.forName(DRIVER_CLASS); } catch (ClassNotFoundException e) { e.printStackTrace(); } conn = DriverManager.getConnection(URL, USER, PASSWORD); stat = conn.createStatement(); rs = stat.executeQuery(sql.toString()); while(rs.next()) { String stuId = rs.getString("stu_id"); String stuName = rs.getString("stu_name"); String stuSex = rs.getString("sex"); String stuAge = rs.getString("stu_age"); String stuPhone = rs.getString("stu_phone"); System.out.println("Student ID:"+stuId+"----"+"Name:"+stuName+"----"+"Gender:"+stuSex+"---"+"Age:"+ stuAge+"----"+"Phone:"+stuPhone); } } catch (SQLException e) { e.printStackTrace(); } finally { if(rs != null) { try { rs.close(); } catch (SQLException e) { e.printStackTrace(); } } if(stat != null) { try { stat.close(); } catch (SQLException e) { e.printStackTrace(); } } if(conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } } 3. Solution Because the executeQuery method was called during the insert operation, an error occurred; the insert operation should call the executeUpdate method int result = stat.executeUpdate(sql.toString());

SQLException: “Can not issue data manipulation statements with executeQuery()” [duplicate]

Không tìm thấy câu trả lời bạn tìm kiếm? Duyệt qua các câu hỏi được gắn thẻ , hoặc hỏi câu hỏi của bạn

키워드에 대한 정보 can not issue data manipulation statements with executequery

다음은 Bing에서 can not issue data manipulation statements with executequery 주제에 대한 검색 결과입니다. 필요한 경우 더 읽을 수 있습니다.

이 기사는 인터넷의 다양한 출처에서 편집되었습니다. 이 기사가 유용했기를 바랍니다. 이 기사가 유용하다고 생각되면 공유하십시오. 매우 감사합니다!

사람들이 주제에 대해 자주 검색하는 키워드 How to MySQL : Cannot issue data manipulation statements with executeQuery()

  • 동영상
  • 공유
  • 카메라폰
  • 동영상폰
  • 무료
  • 올리기

How #to #MySQL #: #Cannot #issue #data #manipulation #statements #with #executeQuery()


YouTube에서 can not issue data manipulation statements with executequery 주제의 다른 동영상 보기

주제에 대한 기사를 시청해 주셔서 감사합니다 How to MySQL : Cannot issue data manipulation statements with executeQuery() | can not issue data manipulation statements with executequery, 이 기사가 유용하다고 생각되면 공유하십시오, 매우 감사합니다.

Leave a Comment