Choose the right Statement
Statement, preparedStatement, and CallableStatement are different objects used to send commands to a database.
A Statement object is used to execute simple SQL statements with no parameters; a PreparedStatement object is used for precompiled SQL statements that may have IN parameters; and a CallableStatement object is used to execute SQL stored procedures, which are groups of SQL statements used to do certain tasks. CallableStatement may have IN, OUT, and INOUT parameters.
There is a misunderstanding that using a PreparedStatement is always faster than using a Statement object. In fact, this is not true. A PreparedStatement object is precompiled and stored for future use. If you want to execute a SQL command several times,
you should use Statement because the time used in precompiling is too long and the benefit will show up only after you use a PreparedStatement for more than 50 ~ 60 times.
CallableStatement is used to handle stored procedures. The reason for using a stored procedure is that you want to execute a series of SQL commands in the same sequence every time. By putting them together, you save the time to move all the related data back and forth over the network. Also, a stored procedure can be compiled before it is used. To improve performance, can we define single Statement as a stored procedure and execute it as CallableStatement? The answer is no. There is some overhead in using stored procedure. If your procedure is very simple, the overhead will hurt the performance. You should use CallableStatement, when you have a complex task that requires several SQL statements to complete.