  复制import java.sql.*;              import sqlj.runtime.*;              import sqlj.runtime.ref.*;              #sql iterator App_Cursor1 (String empno,语应用 String firstnme) ;              #sql iterator App_Cursor2 (String) ;              class App              {              static              {              try              {              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();              }              catch (Exception e)              {              e.printStackTrace();              }              }              public static void main(String argv[])              {              try              {              App_Cursor1 cursor1;              App_Cursor1 cursor2;              String str1 = null;              String str2 = null;              int count1;              Connection con = null;              String url = "jdbc:odbc:tese2";              DefaultContext ctx = DefaultContext.getDefaultContext();              if (ctx == null) {              try {              if (argv.length == 0) {              String userid ="tdl";              String passwd ="user";              con = DriverManager.getConnection(url, userid, passwd);              }              else if (argv.length == 2) {              // connect with default id/password              con = DriverManager.getConnection(url);              }              else {              System.out.println("Usage: java App [username password]");              System.exit(0);              }              con.setAutoCommit(false);              ctx = new DefaultContext(con);              }              catch (SQLException e) {              System.out.println("Error: could not get a default context");              System.err.println(e) ;              System.exit(1);              }              DefaultContext.setDefaultContext(ctx);              }              #sql cursor1 = { SELECT empno, firstnme from db2admin.employee };              System.out.println("Received results:");              while (cursor1.next()) {              str1 = cursor1.empno();              str2 = cursor1.firstnme();              System.out.print (" empno= " + str1);              System.out.print (" firstname= " + str2);              System.out.print ("");              }              cursor1.close();              #sql cursor2 = { SELECT firstnme from db2admin.employee where empno = :str1 };              System.out.println("Received results:");              while (true) {              #sql { FETCH :cursor2 INTO :str2 };              if (cursor2.endFetch()) break;              System.out.print (" empno= " + str1);              System.out.print (" firstname= " + str2);              System.out.print ("");              }              cursor2.close();              // rollback the update              System.out.println("Rollback the update...");              #sql { ROLLBACK work };              System.out.println("Rollback done.");              }              catch( Exception e )              {              e.printStackTrace();              }              }              }             1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.39.40.41.42.43.44.45.46.47.48.49.50.51.52.53.54.55.56.57.58.59.60.61.62.63.64.65.66.67.68.69.70.71.72.73.74.75.76.77.78.79.80.81.82.83.84.85.86.87.88.89.90.91.92.93.94.95.96.97.98.99.100.101.102.103.104.105.106.107.108.109.110.111.112.113.114.115.116.117.118.119.120.121.122.123.124.125.126.127.128.129.130.131.132.133.134.135.136.137.138.139.140.141.142.143.144.145.146.147.148.149.150.151.152.153.154.155.156.157.158.159.160.161.162.163.164.165.166.167.168.169.170.171.172. |