This topic describes the DB2eAppl.java and the DB2eJavaCLP.java sample applications.
Sample 1: DB2eAppl.java
DB2eAppl.java demonstrates how to code a JDBC application for DB2 Everyplace.
The major steps of the DB2eAppl.java application are:
The DB2eAppl.java source code below contains comments that show where the steps explained above are being used.
import java.sql.*; //Step 1 public class DB2eAppl { public static void main(String[] args) { String driver = "com.ibm.db2e.jdbc.DB2eDriver"; String url = "jdbc:db2e:mysample"; try { Class.forName(driver); //Step 2 Connection con = DriverManager.getConnection(url); //Step 3 Statement st = con.createStatement(); //Step 4 //Create table: employee //Step 5 st.executeUpdate("CREATE TABLE employee (EMPNO CHAR(6), FIRSTNAME VARCHAR(12))"); System.out.println("*** Created table: employee"); //Add records to employee st.executeUpdate("INSERT INTO employee VALUES ('112233','John')"); st.executeUpdate("INSERT INTO employee VALUES ('445566','Mary')"); System.out.println("*** Inserted two records"); //Query and display results //Step 6 ResultSet rs = st.executeQuery("SELECT * FROM employee"); System.out.println("*** Query results:"); while (rs.next()) { System.out.print("EMPNO=" + rs.getString(1) + ", "); System.out.println("FIRSTNAME=" + rs.getString(2)); } //Delete table: employee //Step 7 st.executeUpdate("Drop table employee"); System.out.println("*** Deleted table: employee"); rs.close(); st.close(); con.close(); } catch (SQLException sqlEx) { while(sqlEx != null) { System.out.println("[SQLException] " + "SQLState: " + sqlEx.getSQLState() + ", Message: " + sqlEx.getMessage() + ", Vendor: " + sqlEx.getErrorCode() ); sqlEx = sqlEx.getNextException(); } } catch (Exception ex) { ex.printStackTrace(); } } }
Sample 2: DB2eJavaCLP.java
DB2eJavaCLP.java is a Java command line processor for DB2 Everyplace.
Related tasks
Related concepts