ResultSet executeQuery(String sql) throws SQLException :
This method is used for SQL statements which retrieve some data from the database. For example is SELECTstatement. This method is meant to be used for select queries which fetch some data from the database. This method returns one java.sql.ResultSet object which contains the data returned by the query.
int executeUpdate(String sql) throws SQLException :
This method is used for SQL statements which update the database in some way. For example INSERT, UPDATE and DELETE statements. All these statements are DML(Data Manipulation Language) statements. This method can also be used for DDL(Data Definition Language) statements which return nothing. For example CREATE and ALTER statements. This method returns an int value which represents the number of rows affected by the query. This value will be 0 for the statements which return nothing.
boolean execute(String sql) throws SQLException :
This method can be used for all types of SQL statements. If you don’t know which method to use for you SQL statements, then this method can be the best option. This method returns a boolean value. TRUE indicates that statement has returned a ResultSet object and FALSE indicates that statement has returned an int value or returned nothing.
No comments:
Post a Comment