This example shows the code for a WebSphere Application Server Version 4.0 data access JavaBean. The example was created with VisualAge for Java.
See the Code example disclaimer for legal information about this code example.
package examples; import com.ibm.db.uibeans.*; import com.ibm.db.*; /** * This type was created in VisualAge. */ public class SelectStatementExample { /** * GenericTest constructor comment. */ public SelectStatementExample() { super(); } /** * Starts the application. * @param args an array of command-line arguments */ public static void main(java.lang.String[] args) { // Objects SelectStatement stmt = new SelectStatement(); DatabaseConnection conn = new DatabaseConnection(); StatementMetaData metaData = new StatementMetaData(); SelectResult result; // Set properties for connection conn.setDriverName("com.ibm.db2.jdbc.app.DB2Driver"); conn.setDataSourceName("jdbc:db2:Sample"); conn.setUserID("userid"); conn.setPassword("password"); // Set SQL statement metaData.setSQL("SELECT * FROM DEPARTMENT"); // Associate connection and metadata with stmt stmt.setConnection(conn); stmt.setMetaData(metaData); try { // Execute SQL statement stmt.execute(); // Process results result = stmt.getResult(); for (int i = 1; i <= result.getNumRows(); i++) { System.out.println(result.getColumnValueToString(1)); System.out.println(result.getColumnValueToString(2)); result.nextRow(); } // Release JDBC resources result.close(); // Close the database connection conn.disconnect(); } catch (DataException ex) { ex.printStackTrace(); } } }