NamedQuery

This class wraps around a {@link PreparedStatement} and allows the programmer to set parameters by name instead of by index. This eliminates any confusion as to which parameter index represents what. This also means that rearranging the SQL statement or adding a parameter doesn't involve renumbering your indices. Code such as this:

More...

Members

Functions

setParameter
void setParameter(string name, Variant value)
Undocumented in source.
setParameter
void setParameter(string name, R value)
Undocumented in source. Be warned that the author may not have intended to support it.

Inherited Members

From PreparedQuery

getPreparedStatement
PreparedStatement getPreparedStatement()
Undocumented in source.
execute
PreparedQuery execute(RowSetHandler handler)

Calls {@link #execute(Tuple, Handler)} with an empty tuple argument.

execute
PreparedQuery execute(Tuple args, RowSetHandler handler)

Create a cursor with the provided {@code arguments}.

cursor
Cursor cursor()

@return create a query cursor with a {@code fetch} size and empty arguments

cursor
Cursor cursor(Tuple args)

Create a cursor with the provided {@code arguments}.

batch
PreparedQuery batch(List!(Tuple) argsList, RowSetHandler handler)

Execute a batch.

close
void close()

Close the prepared query and release its resources.

close
void close(AsyncVoidHandler completionHandler)

Like {@link #close()} but notifies the {@code completionHandler} when it's closed.

Detailed Description

Connection con=getConnection(); String query="select * from my_table where name=? or address=?"; PreparedStatement p=con.prepareStatement(query); p.setString(1, "bob"); p.setString(2, "123 terrace ct"); ResultSet rs=p.executeQuery();

can be replaced with:

Connection con=getConnection(); String query="select * from my_table where name=:name or address=:address"; NamedParameterStatement p=new NamedParameterStatement(con, query); p.setString("name", "bob"); p.setString("address", "123 terrace ct"); ResultSet rs=p.executeQuery();

Sourced from JavaWorld Article @ http://www.javaworld.com/javaworld/jw-04-2007/jw-04-jdbc.html

Meta