established, most of the time the only code which change is either SQL 
statements or return data types.
The JDBC API does not put any restrictions on the kinds of SQL statements that 
can be executed though JDBC, so it is the application's responsibility to pass 
SQL statements compatible to the database used.
The connection obtained in 
Example 7 38 and Example 7 39 can be used for one of the following three types 
of statements depending upon the requirements:
Statement   Simple single SQL statement
The statement can be created by using the 
createStatement
 method of the 
Connection. Example 7 40 shows the usage of 
executeQuery
 with a change 
for MySQL and DB2 UDB. As we can see in the example the only change in 
this code is the SQL statement.
Example 7 40   Query statement changes from MySQL to DB2 UDB
Statement s = conn.createStatement();
//MySQL statement
s.executeQuery ("SELECT warenkorb.wk_id, warenkorb.user_id,warenkorb.status 
FROM warenkorb"); 
//DB2 UDB statement
s.executeQuery ("SELECT wk_id, user_id,status FROM itsodb.warenkorb"); 
ResultSet rs = s.getResultSet ();
while (rs.next ())
   {
       int id = rs.getInt ("wk_id");
       int uid = rs.getInt("user_id");
       String status = rs.getString ("status");
       System.out.println (
               "id = " + id
               + ", user = " + uid
               + ", status = " + status);
   }
   rs.close ();
   s.close ();
PreparedStatement   Precompiled SQL statements
PreparedStatements are used to effectively execute the statement multiple 
times. Example 7 41 shows the conversion of the prepared statements. 
Setting appropriate values of host variables is very important while using 
prepared statements. In the section titled  Java, JDBC, and SQL data type 
conversions  on page 197 we discuss more about it.
callableStatement   Statement to call stored procedures (only in DB2 UDB)
194 
MySQL to DB2 UDB Conversion Guide






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

san diego web hosting

 

Our partners: PHP: Hypertext Preprocessor Cheap Web Hosting JSP Web Hosting Ontario Web Hosting  Jsp Web Hosting

Cheapest Web Hosting Java Hosting Cheapest Hosting

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