JDBC - PreparedStatement (bind variable, parameter markers)

Jdbc Class Architecture

About

SQL - Prepared Statement in JDBC.

The PreparedStatement interface extends Statement.

See also: JDBC - Batch (Update|Statement) (DML|DDL)

Syntax

Parameter markers, represented by “?” in the SQL string, are used to specify bind variable (input values) to the statement that may vary at runtime.

Connection conn = ds.getConnection(user, passwd);
PreparedStatement ps = conn.prepareStatement(“INSERT INTO BOOKLIST" +
"(AUTHOR, TITLE, ISBN) VALUES (?, ?, ?)”);
ps.setString(1, “Zamiatin, Evgenii”);
ps.setString(2, “We”);
ps.setLong(3, 0140185852L);
ps.setNull(2, java.sql.Types.VARCHAR);
Integer value = new Integer(15);
ps.setObject(1, value, java.sql.Types.SHORT);
Integer value = new Integer(15);
// value is mapped to java.sql.Types.INTEGER
ps.setObject(1, value);

Some driver may support named parameters supportsNamedParameters





Discover More
Jdbc Class Architecture
JDBC - Batch (Update|Statement) (DML|DDL)

The batch update facility allows multiple SQL statements to be submitted to a data source for processing at once. Submitting multiple SQL statements, instead of individually, can greatly improve performance....
Jdbc Class Architecture
Jdbc - Statement

Statement objects are created by Connection objects The java/sql/StatementStatement interface defines methods for executing SQL statements. There is also two subclasses: The PreparedStatement interface...



Share this page:
Follow us:
Task Runner