DB2 10.5 for Linux, UNIX, and Windows

Variables in JDBC applications

As in any other Java™ application, when you write JDBC applications, you declare variables. In Java applications, those variables are known as Java identifiers.

Some of those identifiers have the same function as host variables in other languages: they hold data that you pass to or retrieve from database tables. Identifier empNo in the following code holds data that you retrieve from the EMPNO table column, which has the CHAR data type.

String empNo;
// Execute a query and generate a ResultSet instance
rs = stmt.executeQuery("SELECT EMPNO FROM EMPLOYEE");
while (rs.next()) {
 String empNo = rs.getString(1);
 System.out.println("Employee number = " + empNo);
}

Your choice of Java data types can affect performance because the data server picks better access paths when the data types of your Java variables map closely to the data server data types.