89 lines
2.5 KiB
HTML
89 lines
2.5 KiB
HTML
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||
|
<html>
|
||
|
<head>
|
||
|
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||
|
<LINK rel="stylesheet" type="text/css" href="../../../rzahg/ic.css">
|
||
|
|
||
|
<title>Example: Using WebSphere Application Server Version 4.0 data access beans</title>
|
||
|
</head>
|
||
|
|
||
|
<BODY>
|
||
|
<!-- Java sync-link -->
|
||
|
<SCRIPT LANGUAGE="Javascript" SRC="../../../rzahg/synch.js" TYPE="text/javascript"></SCRIPT>
|
||
|
|
||
|
<h6><a name="dabex1"></a>Example: Using WebSphere Application Server Version 4.0 data access beans</h6>
|
||
|
|
||
|
<p>This example shows the code for a WebSphere Application Server Version 4.0 data access JavaBean. The example was created with VisualAge for Java.</p>
|
||
|
|
||
|
<p>See the <a href="codex.htm">Code example disclaimer</a> for legal information about this code example.</p>
|
||
|
|
||
|
<pre>package examples;
|
||
|
|
||
|
import com.ibm.db.uibeans.*;
|
||
|
import com.ibm.db.*;
|
||
|
/**
|
||
|
* This type was created in VisualAge.
|
||
|
*/
|
||
|
|
||
|
public class SelectStatementExample {
|
||
|
/**
|
||
|
* GenericTest constructor comment.
|
||
|
*/
|
||
|
|
||
|
public SelectStatementExample() {
|
||
|
super();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Starts the application.
|
||
|
* @param args an array of command-line arguments
|
||
|
*/
|
||
|
public static void main(java.lang.String[] args) {
|
||
|
|
||
|
// Objects
|
||
|
SelectStatement stmt = new SelectStatement();
|
||
|
DatabaseConnection conn = new DatabaseConnection();
|
||
|
StatementMetaData metaData = new StatementMetaData();
|
||
|
SelectResult result;
|
||
|
|
||
|
// Set properties for connection
|
||
|
conn.setDriverName("com.ibm.db2.jdbc.app.DB2Driver");
|
||
|
conn.setDataSourceName("jdbc:db2:Sample");
|
||
|
conn.setUserID("userid");
|
||
|
conn.setPassword("password");
|
||
|
|
||
|
// Set SQL statement
|
||
|
metaData.setSQL("SELECT * FROM DEPARTMENT");
|
||
|
|
||
|
// Associate connection and metadata with stmt
|
||
|
stmt.setConnection(conn);
|
||
|
stmt.setMetaData(metaData);
|
||
|
|
||
|
try {
|
||
|
// Execute SQL statement
|
||
|
stmt.execute();
|
||
|
|
||
|
// Process results
|
||
|
result = stmt.getResult();
|
||
|
for (int i = 1; i <= result.getNumRows(); i++) {
|
||
|
System.out.println(result.getColumnValueToString(1));
|
||
|
System.out.println(result.getColumnValueToString(2));
|
||
|
result.nextRow();
|
||
|
}
|
||
|
|
||
|
// Release JDBC resources
|
||
|
result.close();
|
||
|
|
||
|
// Close the database connection
|
||
|
conn.disconnect();
|
||
|
}
|
||
|
catch (DataException ex) {
|
||
|
ex.printStackTrace();
|
||
|
}
|
||
|
}
|
||
|
}</pre>
|
||
|
|
||
|
</body>
|
||
|
</html>
|
||
|
|