PreparedStatement object differs from Statement object as that it is used to create a statement in standard form that is sent to database for compilation, before actually being used.
Each time you use it, you simply replace some of the marked parameters (?) using some setter methods.
We can create PreparedStatement object by using prepareStatementmethod of the connection class.
The SQL query is passed to this method as an argument as shown below. PreparedStatement pStmt = con.prepareStatement (“UPDATE tableName SET columnName = ? ” + “WHERE columnName =?”);
Notices that we used marked parameters (?) in query. We will replace them later on by using various setter methods.
If we want to replace first? With String value, we use setString method and to replace second? With int value, we use setInt method. This is shown in the following code snippet.
pStmt.setString (1 , stringValue); pStmt.setInt (2 , intValue)
0 Comments
Please add nice comments or answer ....