My question is: What are the datatypes I should support for a Javabean to fill a PreparedStatement?
I’m writing a SQLHelper for a Java Helper Library. One of the classes I’m writing is a QueryParameter Javabean which holds a type and value. It’s main use is to be associated with a HelperQuery Javabean and a prepared statement will be filled with them in a call like this to the following method:
fillStatement(preparedStatement, helperQuery.getParams());
public void fillStatement(PreparedStatement pstmt, QueryParameter... params) throws SQLException {
for (int i = 1; i <= params.length; i++) {
QueryParameter param = params[i - 1];
switch (param.getType()) {
case QueryParameter.CLOB:
pstmt.setClob(i, (Clob) clob);
break;
case QueryParameter.STRING:
pstmt.setString(i, (String) param.getValue());
break;
case QueryParameter.YOU_GET_THE_IDEA:
//...;
break;
}
}
}
Take a look at the PreparedStatement javadoc and support every
setSomethingdatatype there. They are: