PreparedStatement
Statement will compile it when executing SQL. The PreparedStateMent component inherits from statement, which can be compiled and stored in advance. Since SQL has been compiled in advance, the efficiency of the execution is better. For pre-compiled SQL , Can be used? Represents a replaced parameters, for example: preparedStatement Stmt = conn.preparedStatement ("INSERT INTO Message Valuse (",,?,?,?) "); To specify parameters to each field bit, you can use Setint (), setString (), etc., for example: Stmt.setString (1, "michael chen"); stmt.setstring (2, "blog.9cbs.net/ybugchen); stmt.setstring (3," message " ); Stmt.setString (4, "2005-2-4"); Stmt.setString (5, "Welcome"); stmt.executeUpdate (); stmt.clearparameters (); setxxx () method of the first parameter specified Where the position, the second parameter is the value to be added to the database record field. To perform executeUpdate () or executeQuery () can be a SQL statement take effect, using setXXX () to specify the parameters that will be valid, if you want to clean the settings Parameters, execute a ClearParameters () method. Batch processing can also be performed using PreparedStatement, for example: preparedStatement Stmt = conn.preparestatement ("INSERT INTO users VALUES (?,?)"); User [] users = ... // User defines a data structure class for (INT i = 0; i