I assume that the operator is used in queries without parameters, but why not use a prepared statement?
It is not even close. PreparedStatements are used for INSERT, UPDATE, and DELETE statements that return a ResultSet or the number of updates. They will not work for DDL statements, as pointed out by Joachim, and they will not work for calling stored procedures in which CallableStatement must be used (this is not the difference between the two classes). For queries without binding parameters, PreparedStatements may turn out to be better than statements (see below).
Which one is faster for queries without parameters.
PreparedStatements will run faster in the long run, with longer use in a single connection. This is due to the fact that although PreparedStatements needs to be compiled, which takes some time (it really isnโt so much, so donโt see it as a drawback), the compiled version essentially contains a link to the SQL execution plan in the database. After compilation, the PreparedStatement is stored in a connection-specific cache, so that the compiled version can be reused to achieve improved performance. If you use JDBC batch operations, using PreparedStatements will make batch execution much faster than using simple Statement objects, where you may have to prepare the plan again and again if the database needs to do this.
Vineet reynolds
source share