The three methods in the connection interface can be used to create instances of these classes. These classes and their creation methods are listed below:
(1) Statement-created by the createstatement method. The statement object is used to send simple SQL statements.
(2) preparedstatement-created by the preparestatement method.
(3) The preparedstatement object is used to send an SQL statement with one or more input parameters (in parameters. Preparedstatement has a set of methods used to set the value of the in parameter.
When a statement is executed, these in parameters are sent to the database. Preparedstatement instances extend the statement, so they all include the statement method.
The preparedstatement object may be more efficient than the statement object because it has been precompiled and stored there for future use.
Callablestatement-created by the preparecall method. Callablestatement object is used to execute SQL StorageProgram-A group of SQL statements that can be called by name (just like a function call. The callablestatement object inherits the methods used to process the in parameter from the preparedstatement object, and also adds methods used to process the out and inout parameters.
The methods listed below can quickly decide which connection method to apply to create different types of SQL statements:
The createstatement method is used for simple SQL statements (without parameters ).
The preparestatement method is used to execute simple SQL statements that contain one or more in parameters.
The preparecall method is used to call the stored procedure.