PreparedStatement vs Statement
Similarities and Differences:
Code readability and maintainability.PreparedStatement can maximize performance:
DBServer optimizes the performance of precompiled statements. Because pre-compiled statements may be called
Perparedstatement interface Detailed:One, JDBC Tool class extensions:
The close () method overloads public
static void Close (Connection conn,statement Stmt,resultset rs) {
if (rs!=null) {
try {
rs.close ();
first, what is PreparedStatementIn the Java API documentation, we can see that PreparedStatement is the statement sub-interface () object that represents the precompiled SQL statement, and the SQL statement is precompiled and stored in
In the previous "Java programming" build a simple JDBC connection-drivers, Connection, Statement and PreparedStatement we described how to use the JDBC driver to establish a simple connection, and realize the use of statement and PreparedStatement
1, the definition of PreparedStatementPreparedStatement is an interface under the JAVA.SQL package that executes SQL statement queries that can be obtained preparedstatment objects by invoking the Connection.preparedstatement (SQL) method. The
exception of setstring method in PreparedStatement
In fact, should not be said to be abnormal, should be a variety of factors caused by the use of the problem.Generally after having a certain Java programming experience, everyone is accustomed to
In JDBC applications, if you are already a relatively level developer, you should always replace statement with preparedstatement. That is to say, do not use statement at any time.
For the following reasons:
I. code readability and
In JDBC applications, if you are already a relatively level developer, you should always replace statement with preparedstatement. That is to say, do not use statement at any time.
For the following reasons:
I. code readability and
When updating a large amount of data, prepare an insert statement is executed multiple times, which may lead to many network connections. to reduce the number of JDBC calls and improve performance, you can use the addbatch () method of
Write code today when you need to insert a date type into the database time, use to preparedstatement the time to find Setdate () method always give me prompt error, the results of a check, found PreparedStatement setdate () The time type of the
1.statement Inconvenient to useProblems with 2.sql injection* Use the system's own keyword OR and in the SQL statement to invalidate the Where condition*Preparestatement:* 1.sql statements are not used in the spelling string* 2. Prevent SQL
The PreparedStatement class inherits from the statement.SQL statements can be passed to the database for compilation, that is, the executed SQL statement contains one or more in parameters, you can set the in parameter value to execute the SQL
This blog provides a simple JDBC connection routine through the JDBC driver, and realizes the query to the database through statement and PreparedStatement respectively. The next blog will focus on the differences between statement and
PreparedStatement object Compared to statement object1, the readability and maintainability of the code.2, PreparedStatement can guarantee security (solve SQL injection problem)3, PreparedStatement can improve the performance of the maximum possible:
In a JDBC application, if you are already a slightly level developer, you should try to replace statement with PreparedStatement. That is, do not use statement in most cases. This is based on the following reasons: I. Readability and
From the code point of view, using PreparedStatement instead of statement will make the code a few more lines, but such code in terms of readability or maintainability, than the direct use of statement code much higher grade.The arguments passed to
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.