EasyManuals Logo

IBM DB2 User Manual

IBM DB2
585 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #449 background imageLoading...
Page #449 background image
com.ibm.db2.jcc.DB2Version.getVersion());
// Connect to the local DB2 for z/OS server
System.out.println("\nEstablishing connection to local server");
Connection conn = DriverManager.getConnection("jdbc:db2:");
System.out.println(" Successful connect");
conn.setAutoCommit(false);
// Use DatabaseMetaData to determine the DB2 version
System.out.println("\nAcquiring DatabaseMetaData");
DatabaseMetaData dbmd = conn.getMetaData();
System.out.println(" DB2 version: " +
dbmd.getDatabaseProductVersion());
// Create a Statement object for executing a query
System.out.println("\nCreating Statement");
Statement stmt = conn.createStatement();
System.out.println(" successful creation of Statement");
// Execute the query and retrieve the ResultSet object
String sqlText =
"SELECT CREATOR, " +
"NAME " +
"FROM SYSIBM.SYSTABLES " +
"ORDER BY CREATOR, NAME";
System.out.println("\nPreparing to execute SELECT");
ResultSet results = stmt.executeQuery(sqlText);
System.out.println(" Successful execution of SELECT");
// Retrieve and display the rows from the ResultSet
System.out.println("\nPreparing to fetch from ResultSet");
int recCnt = 0;
while(results.next())
{
String creator = results.getString("CREATOR");
String name = results.getString("NAME");
System.out.println("CREATOR: <" + creator + "> NAME: <" + name + ">");
recCnt++;
if(recCnt == 10) break;
}
System.out.println(" Successful processing of ResultSet");
// Close the ResultSet, Statement, and Connection objects
System.out.println("\nPreparing to close ResultSet");
results.close();
System.out.println(" Successful close of ResultSet");
System.out.println("\nPreparing to close Statement");
stmt.close();
System.out.println(" Successful close of Statement");
System.out.println("\nPreparing to rollback Connection");
conn.rollback();
System.out.println(" Successful rollback");
System.out.println("\nPreparing to close Connection");
conn.close();
System.out.println(" Successful close of Connection");
}
// Handle errors
catch(ClassNotFoundException e)
{
System.err.println("Unable to load IBM Data Server Driver " +
"for JDBC and SQLJ,"+e);
}
catch(SQLException e)
{
Chapter 8. Installing the IBM Data Server Driver for JDBC and SQLJ 433

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the IBM DB2 and is the answer not in the manual?

IBM DB2 Specifications

General IconGeneral
DeveloperIBM
Initial Release1983
LicenseProprietary
Written inC, C++
CategoryDatabase Management System (RDBMS)
Operating SystemLinux, Windows
Programming LanguagesC, C++
Data ModelsRelational
EditionsCommunity, Standard, Advanced
Key Featureshigh availability, scalability