String uid= db2inst1 ;
String pwd= ibmdb2 ;
Connection con=null;
try {
con=DriverManager.getConnection(url, uid, pwd)
} catch (SQLException e) {
e.printStackTrace();
}
Creating the DB2 statement
Each time we need to execute an SQL statement, we must create a
statement first. This is done with the following code (we assume the
connection variable
con
has already been created and assigned to. See
 Creating the DB2 connection  on page 84):
Statement stmt=con.createStatement();
Executing the DB2 statement
With this statement, we can now perform two types of SQL statements:
  Inserts/Update/Deletes
SQL inserts, updates, and deletes return the number of rows affected by
the SQL statement. We would use the executeUpdate method to execute
these SQL statements. The method returns the number of rows affected
by the SQL statement, of type integer. Hence, we could code the following
to delete all rows from the USERINFO table where the username equals
 alistair  as follows:
String sqlStmt= delete from userinfo where username='alistair' ;
int rsi=stmt.executeUpdate(sqlStmt);
  Queries
SQL queries return a set of rows. This is called a result set of rows. Use
the method executeQuery from the statement, which returns a type of
ResultSet. We could code a simple SQL query to select all rows from the
USERINFO table as follows:
String sqlStmt= select * from USERINFO 
ResultSet rs=stmt.executeQuery(sqlStmt);
To obtain each result set row, we use the next() method. This method
returns true if there is a next result set row, and it is intially positioned
before the first result set row. For example:
if (rs.next()) {
// process next result set row
}
Chapter 3. Building the Web server
85




  

Home

About Services Network Support FAQ Order Contact
 

Linux Web Hosting

Our partners:Jsp Web Hosting Unlimited Web Hosting Cheapest Web Hosting  Java Web Hosting Web Templates Best Web Templates PHP Mysql Web Hosting Interland Web Hosting Cheap Web Hosting PHP Web Hosting Tomcat Web Hosting Quality Web Hosting Best Web Hosting  Mac Web Hosting 

Lunarwebhost.net  Business web hosting division of Vision Web Hosting Inc. All rights reserved