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

68 lines
1.9 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 - Express data access beans</title>
</head>
<BODY>
<!-- Java sync-link -->
<SCRIPT LANGUAGE="Javascript" SRC="../../../rzahg/synch.js" TYPE="text/javascript"></SCRIPT>
<h6><a name="dabex2"></a>Example: Using WebSphere Application Server - Express data access beans</h6>
<p>This example shows the code for a WebSphere Application Server - Express data access JavaBean.</p>
<p>See the <a href="codex.htm">Code example disclaimer</a> for legal information about this code example.</p>
<pre>package example;
import com.ibm.db.beans.*;
import java.sql.SQLException;
public class DBSelectExample {
public static void main(String[] args) {
DBSelect select = null;
select = new DBSelect();
try {
// Set database connection information
select.setDriverName(&quot;com.ibm.db2.jdbc.app.DB2Driver&quot;);
select.setUrl(&quot;jdbc:db2:SAMPLE&quot;);
select.setUsername(&quot;userid&quot;);
select.setPassword(&quot;password&quot;);
// Specify the SQL statement to be executed
select.setCommand(&quot;SELECT * FROM DEPARTMENT&quot;);
// Execute the statement and retrieve the result set into the cache
select.execute();
// If result set is not empty
if (select.onRow()) {
do {
// display first column of result set
System.out.println(select.getColumnAsString(1));
System.out.println(select.getColumnAsString(2));
} while (select.next());
}
// Release the JDBC resources and close the connection
select.close();
}
catch (SQLException ex) {
ex.printStackTrace();
}
}
}</pre>
</body>
</html>