HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML

"JDBC 3.0 - Something for Everyone"
Vol. 7, Issue 5, p. 60


Listing 1

Statement stmt = conn.createStatement ();

Int  rowcount = stmt.executeUpdate ("insert into etable (event) values ('TMM')");

Int rowcount = stmt.executeUpdate ("insert into costs (cost) values (45.0)");

Savepoint sv1 = conn.setSavePoint ("svpoint1");  
// create savepoint for inserts

Int rowcount = stmt.executeUpdate ("delete from employees");     

Conn.rollback (sv1);   
//  discard the delete statement but keep the inserts

// inserts are now permanent

Listing 2

// Retrieve the case history for incident 71164
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery (
		"select CaseHistory from Cases where IncidentID=71164");

rs.next();  // position to the row
Blob data = rs.getClob (1);   
// populate our Blob object with the data

// now letšs insert this history into another table
stmt.setClob (1, data);   
// data is Clob object we retrieved from the history table

int InsertCount = stmt.executeUpdate (
"insert into EscalatedIncidents (IncidentID, CaseHistory, Owner)"
+ " Values (71164, ?, 'Goodson') ");

// wešre done ... CLOB data is now in the database

Listing 3

// get ready to call the employeeInfo procedure
CallableStatement cstmt = conn.prepareCall ("{call employeeInfo (?)}");

Cstmt.setInt (1,71164);   
// bind parameter info for employee with id 71164

Boolean RetCode = Cstmt.execute ();   
// call the procedure
// For simplicity wešll bypass logic for the procedure possibly returning update counts

// first result set will be discarded ... materialize it and immediately move to the second
ResultSet DiscardRS = cstmt.getResultSet();      
// materialize first result set

ResultSet EmpListRS = cstmt.getMoreResults ();  
// by default, close DiscardRS
// the 2nd result set: list of employees that report to 71164 is now available

ResultSet ProjectsRS = cstmt.getMoreResults (KEEP_CURRENT_RESULT);
// the 3rd result set is now materialized and we can simultaneously operate on both
//    the employee list and the project list


All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.