![]() |
The NetRexx Tutorial
- Database Operations
|
Introduction An interface to some primitive database functions is available as a NetRexx extension.
*** This section is:*** and will be available in next releases
Use NetRexx with JDBC The following code atom shows how to use NetRexx with JDBC
+----------------------------------------------------------------------+
| -- original sample from Gerhard Hofstaetter (hofg@edvg.co.at) |01
| -- and posted on ibm-netrexx |02
| -- use NetRexx with JDBC |03
| -- |04
| import java.net.URL |05
| import java.sql. |06
| import ibm.sql. |07
| |08
| class jdbct1 |09
| |10
| method jdbct1 |11
| class.forName('ibm.sql.DB2Driver') |12
| |13
| method main( args = string[]) static |14
| jdbct1() |15
| |16
| -- set database as URL |17
| url = 'jdbc:db2:edvr0s3' |18
| |19
| -- connect to database |20
| connect = DriverManager.getConnection(url) |21
| |22
| |23
| -- retrieve data from the database |24
| say 'Retrieve some data from the database...' |25
| sqlstmt = connect.createStatement() |26
| resultset = - |27
| sqlstmt.executeQuery('select tabschema, tabname' - |28
| 'from syscat.tables') |29
| |30
| -- display the result set |31
| -- resultset.next() returns false when there are no more rows |32
| say 'Received results:' |33
| loop while resultset.next() |34
| owner = resultset.getString(1) |35
| table = resultset.getString(2) |36
| say 'Owner =' owner 'Table =' table |37
| end |38
| |39
| resultset.close() |40
| sqlstmt.close() |41
| connect.close() |42
+----------------------------------------------------------------------+
jdbct1.nrx
|
|
Download the source for the jdbct1.nrx example
*** This section is:*** and will be available in next releases