Sample Code for a Batch Update
import java.sql.*;
  
public class BatchUpdate {
  
  public static void main(String args[]) {
  
    String url = "jdbc:mySubprotocol:myDataSource";
    Connection con;
    Statement stmt;
    try {
      Class.forName("myDriver.ClassName");
    } catch(java.lang.ClassNotFoundException e) {
      System.err.print("ClassNotFoundException: ");
      System.err.println(e.getMessage());
    }
    try {
     
      con = DriverManager.getConnection(url,
                                        "myLogin", 
                                        "myPassword");
  
      con.setAutoCommit(false);
      stmt = con.createStatement();      stmt.addBatch("INSERT INTO COFFEES " +
               "VALUES('Amaretto', 49, 9.99, 0, 0)");
      stmt.addBatch("INSERT INTO COFFEES " +
               "VALUES('Hazelnut', 49, 9.99, 0, 0)");
      stmt.addBatch("INSERT INTO COFFEES " +
               "VALUES('Amaretto_decaf', 49, 
               10.99, 0, 0)");
      stmt.addBatch("INSERT INTO COFFEES " +
               "VALUES('Hazelnut_decaf', 49, 
               10.99, 0, 0)");      int [] updateCounts = stmt.executeBatch();
      con.commit();
      con.setAutoCommit(true);
      ResultSet rs = stmt.executeQuery(
                       "SELECT * FROM COFFEES");      System.out.println(
        "Table COFFEES after insertion:");
      while (rs.next()) {
        String name = rs.getString("COF_NAME");
        int id = rs.getInt("SUP_ID");
        float price = rs.getFloat("PRICE");
        int sales = rs.getInt("SALES");
        int total = rs.getInt("TOTAL");
        System.out.print(
          name + "   " + id + "   " + price);
        System.out.println(
          "   " + sales + "   " + total);
      }      rs.close();
      stmt.close();
      con.close();    } catch(BatchUpdateException b) {
      System.err.println(
        "----BatchUpdateException----");
      System.err.println(
                 "SQLState:  " + b.getSQLState());
      System.err.println("Message:  " + b.getMessage());
      System.err.println(
        "Vendor:  " + b.getErrorCode());
      System.err.print("Update counts:  ");
      int [] updateCounts = b.getUpdateCounts();
      for (int i = 0; 
           i < updateCounts.length; i++) {
        System.err.print(updateCounts[i] + "   ");
      }
      System.err.println("");      } catch(SQLException ex) {
      System.err.println("----SQLException----");
      System.err.println(
                 "SQLState:  " + ex.getSQLState());
      System.err.println(
                 "Message:  " + ex.getMessage());
      System.err.println(
                 "Vendor:  " + ex.getErrorCode());
    }
  }

--------------------------------------------------------------------------------

解决方案 »

  1.   

    Sample Code for Creating an SQL REF
    import java.sql.*;public class CreateRef {  public static void main(String args[]) {    String url = "jdbc:mySubprotocol:myDataSource";    Connection con;
        Statement stmt;
        try {
          Class.forName("myDriver.ClassName");    
     
        } catch(java.lang.ClassNotFoundException e) {
          System.err.print("ClassNotFoundException: ");
          System.err.println(e.getMessage());
        }      try {
          String createManagers = 
            "CREATE TABLE MANAGERS OF MANAGER " +
            "(OID REF(MANAGER) VALUES ARE SYSTEM GENERATED)";      String insertManager1 = "INSERT INTO MANAGERS " +
            "(MGR_ID, LAST_NAME, FIRST_NAME, PHONE) VALUES " +
            "(000001, 'MONTOYA', 'ALFREDO', '8317225600')";      String insertManager2 = "INSERT INTO MANAGERS " +
            "(MGR_ID, LAST_NAME, FIRST_NAME, PHONE) VALUES " +
            "(000002, 'HASKINS', 'MARGARET', '4084355600')";       String insertManager3 = "INSERT INTO MANAGERS " +
            "(MGR_ID, LAST_NAME, FIRST_NAME, PHONE) VALUES " +
            "(000003, 'CHEN', 'HELEN', '4153785600')";      con = DriverManager.getConnection(url,
                      "myLogin", "myPassword");      stmt = con.createStatement();
          stmt.executeUpdate(createManagers);      con.setAutoCommit(false);       stmt.addBatch(insertManager1);
          stmt.addBatch(insertManager2);
          stmt.addBatch(insertManager3);
          int [] updateCounts = stmt.executeBatch();      con.commit();
     
          System.out.println("Update count for:  ");
          for (int i = 0; i < updateCounts.length; i++) {
            System.out.print(
              "    command " + (i + 1) + " = ");
            System.out.println(updateCounts[i]);
          }
     
          stmt.close();
          con.close();
     
        } catch(BatchUpdateException b) {
          System.err.println(
            "-----BatchUpdateException-----");
          System.err.println("Message:  " + b.getMessage());
          System.err.println(
            "SQLState:  " + b.getSQLState());
          System.err.println("Vendor:  " + b.getErrorCode());
          System.err.print(
            "Update counts for successful commands:  ");
          int [] rowsUpdated = b.getUpdateCounts();
          for (int i = 0; i < rowsUpdated.length; i++) {
            System.err.print(rowsUpdated[i] + "   ");
          }
          System.err.println("");
        } catch(SQLException ex) {
          System.err.println("------SQLException------");
          System.err.println(
            "Error message:  " + ex.getMessage());
          System.err.println(
            "SQLState:  " + ex.getSQLState());
          System.err.println(
            "Vendor:  " + ex.getErrorCode());
        }
      }
    }
      

  2.   

    上面那位人兄,人家好象问BLOB的读取,你的代码一个BLOB的字符也没有哦。写两个例子有什么用啊。
    EJB里读取BLOB也没有什么特别,你可以查找java,jsp论坛找“BLOB”,有很多读取BLOB的例子,在EJB里写就可以。
    [email protected]
      

  3.   

    skyyoung(路人甲) , 我用Container managed EnityBean 读写ejb,你有这方面的经验吗?
      

  4.   

    另外请教,有没有用过java里面的blob类?如何使用啊?我的email: [email protected], 我们讨论一下?
      

  5.   

    http://www.csdn.net/expert/TopicView.asp?id=83096