{"id":120,"date":"2023-05-14T11:48:59","date_gmt":"2023-05-14T11:48:59","guid":{"rendered":"https:\/\/itnotes.apjsoftwares.com\/?p=120"},"modified":"2023-05-14T11:48:59","modified_gmt":"2023-05-14T11:48:59","slug":"what-is-the-difference-between-execute-executequery-executeupdate","status":"publish","type":"post","link":"https:\/\/itnotes.apjsoftwares.in\/index.php\/2023\/05\/14\/what-is-the-difference-between-execute-executequery-executeupdate\/","title":{"rendered":"What is the difference between execute, executeQuery, executeUpdate?"},"content":{"rendered":"\n<p>Statement&nbsp;<strong><em>execute(String query)<\/em><\/strong>&nbsp;is used to execute any SQL query and it returns TRUE if the result is an ResultSet such as running Select queries. The output is FALSE when there is no ResultSet object such as running Insert or Update queries. We can use&nbsp;<em>getResultSet()<\/em>&nbsp;to get the ResultSet and&nbsp;<em>getUpdateCount()<\/em>&nbsp;method to retrieve the update count.<\/p>\n\n\n\n<p>Statement&nbsp;<strong><em>executeQuery(String query)<\/em><\/strong>&nbsp;is used to execute Select queries and returns the ResultSet. ResultSet returned is never null even if there are no records matching the query. When executing select queries we should use executeQuery method so that if someone tries to execute insert\/update statement it will throw java.sql.SQLException with message \u201cexecuteQuery method can not be used for update\u201d.<\/p>\n\n\n\n<p>Statement&nbsp;<strong>executeUpdate(String query<\/strong>) is used to execute Insert\/Update\/Delete (DML) statements or DDL statements that returns nothing. The output is int and equals to the row count for SQL Data Manipulation Language (DML) statements. For DDL statements, the output is 0.<\/p>\n\n\n\n<p>You should use execute() method only when you are not sure about the type of statement else use executeQuery or executeUpdate method.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Statement&nbsp;execute(String query)&nbsp;is used to execute any SQL query and it returns TRUE if the result&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[12],"tags":[],"_links":{"self":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts\/120"}],"collection":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/comments?post=120"}],"version-history":[{"count":1,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts\/120\/revisions"}],"predecessor-version":[{"id":121,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts\/120\/revisions\/121"}],"wp:attachment":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/media?parent=120"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/categories?post=120"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/tags?post=120"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}