the difference between execute, executeupdate, and ExecuteQuery (and the return value)
One, Boolean execute (String sql)
allows the execution of query statements, UPDATE statements, and DDL statements.
when the return value is true, a query statement is executed, the result can be obtained by the Getresultset method, and when the return value is false, an UPDATE statement or a DDL statement is executed, and the Getupdatecount method gets the number of updated records.
Example:
<span style= "FONT-SIZE:16PX;" ><strong>public static void Main (string[] args) { connection conn = null; statement stm
= NULL;
resultset rs = null; try { class.forname ("Com.microsoft.sqlserver.jdbc.SQLServerDriver"); conn = Drivermanager.getconnection ("jdbc:sqlserver://localhost:1433;databasename=test;user=sa;password=
Sasa ");
stm = Conn.createstatement ();
boolean ret = Stm.execute ("SELECT * from Stuinfo"); if (ret) { rs = Stm.getresultset (); while (Rs.next ( ) { system.out.println ("Name:" +rs.getstring ("stuname") + "\ T Age:" +rs.getstring ("
Stuscore ")); &NBSP;&NBSP;&NBSP;&NBSP}  } ret = Stm.execute ("Update stuinfo set stuScore=62
Where Stuname= ' John ');
int count = Stm.getupdatecount (); if (!ret) { &nbsP;&NBSP;&NBSP;SYSTEM.OUT.PRINTLN (count+) data modification succeeded.
"); &NBSP;&NBSP;&NBSP}  } catch (ClassNotFoundException e) { e.printstacktrace (); &NBSP} catch (SQLException e) { e.printstacktrace (); } }</strong ></span>
two, int executeupdate (String sql)
executes the given SQL statement, which may be an INSERT, UPDATE, or DELETE statement, or an SQL statement that does not return any content, such as a SQL DDL statement.
The return value is the number of records updated
III. ResultSet executequery (String sql)
executes the given SQL statement, which returns a single ResultSet object.
Execute is the synthesis of executeupdate and ExecuteQuery
Reference: executeupdate return value Baidu