ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzatz_5.4.0.1/51/program/dabex1.htm

89 lines
2.5 KiB
HTML
Raw Normal View History

2024-04-02 14:02:31 +00:00
<!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(&quot;com.ibm.db2.jdbc.app.DB2Driver&quot;);
conn.setDataSourceName(&quot;jdbc:db2:Sample&quot;);
conn.setUserID(&quot;userid&quot;);
conn.setPassword(&quot;password&quot;);
// Set SQL statement
metaData.setSQL(&quot;SELECT * FROM DEPARTMENT&quot;);
// 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 &lt;= 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>