Hi Jennifer
Prepared statemtns are basically precompiled SQL statements that can be used to speed up processing of the queries when just a few of the parameters of the statement are going to change.
You create them the same as you do a regular Statment object except that you have to include the SQL text in the constructor:
PreparedStatement pStmt = conn.prepareStatement(“SELECT * FROM employees WHERE lname = ?” ;) ;
The question mark represents the parameter to be supplied later. You can have multiple parameters and then later, when you start working with them, they are all referenced with an index starting at 1 (the first parameter is 1 the second is 2 and so on).
Now when you go to use it you have to:
1 clear any existing parameters
--- pStmt.clearParameters( );
2 set the values of any parameters in the statement
--- pStmt.setString(1, “O'Connor” ;) ;
3 execute the statement as normal
--- pStmt.executeQuery();
There are multiple setXXX() methods that all take a parameter index as their first argument and the value being assigned as the second. To assign null, use the setNull() method the first arg would be the parameter index the second is the type of the argument that is being set to null, like this:
pStmt.setNull(2, Types.INTEGER);
Then you just process the results as normal.
hope that helps you out, if you need more details let me know...
[ April 05, 2002: Message edited by: Dave Vick ]