This content has been marked as final. Show 4 replies
Welcome to the forum!
Please let me know in which scenario we are using Statement,Prepared Statement and callable statement.
We don't know what scenario you are using those in or if you are using them at all. Are you asking what they are?
For document related questions you should consult the documentation or use your favorite search engine to get information.
See the Java Tutorial
The main feature of a PreparedStatement object is that, unlike a Statement object, it is given a SQL statement when it is created. The advantage to this is that in most cases, this SQL statement is sent to the DBMS right away, where it is compiled. As a result, the PreparedStatement object contains not just a SQL statement, but a SQL statement that has been precompiled. This means that when the PreparedStatement is executed, the DBMS can just run the PreparedStatement SQL statement without having to compile it first.
The Javadocs for your Java SDK have the API for each of those classes and a description of what they are. And the Oracle JDBC Developer Guide has extensive information on how to use them.
Thanks for the quick response....
Let say if i've below two scenarios
1.To insert the login information to database(firstnamre,lastname and so on).
2.To cheeck the username and password from database(valid/invalid) .
In the above scenario please let me know in which case i need to use statement/prepared statement.
Thanks again !
You need to use PreparedStatement.
Short explanation: Always use PreparedStatement.
Slightly longer explanation: Always use PreparedStatement unless it can't possibly be made to work because of very strange requirements, in which case use Statement.
Reason: It's easier to write the code, it's easier to understand the code, and it removes the exposure to SQL injection attacks.