http://java.sun.com/j2se/1.5.0/docs/api/javax/sql/rowset/CachedRowSet.html http://www.onjava.com/pub/a/onjava/2004/06/23/cachedrowset.html http://java.sun.com/products/jdbc/download.html#rowset1_0_1 

解决方案 »

  1.   

    package rule;import java.sql.*;
    import java.util.Collections;
    import java.util.Hashtable;
    import java.util.Vector;import javax.sql.rowset.CachedRowSet;import com.sun.rowset.CachedRowSetImpl;import rule.db.*;public class TableInstance {    public TableInstance(Vector c, ISet iSet, int k) throws SQLException {
            int start = DbTools.getTableStartId();        Connection conn = DBConnection.getConnection();
            Statement stmt = conn.createStatement();
            conn.setAutoCommit(false);        for (int i = 0; i < c.size(); i++) {
                String type = (String) c.elementAt(i);
                /*
                 * stmt.execute("INSERT INTO TBL_TYPES (K, TYPE) VALUES (" + k + ", " +
                 * type + ")");
                 */
                start = start + i + 1;
                String tblName = "T" + start;
                stmt.execute("CREATE TABLE " + tblName + "(" + type
                        + " INTEGER, id integer)");
                stmt
                        .execute("INSERT INTO TBL_TBLNAMES (ID, K, TABLENAME, TYPESTR) VALUES ("
                                + start
                                + ", "
                                + k
                                + ", '"
                                + tblName
                                + "', '"
                                + type + "')");
                // for (int j = 0; j < iSet.getInstanceNumber(); j++) {
                Vector ids = iSet.getIdByType(type);
                for (int z = 0; z < ids.size(); z++) {
                    int id = ((Integer) ids.elementAt(z)).intValue();
                    stmt.execute("INSERT INTO " + tblName + "(" + type
                            + ", id) values(" + id + ", 0)");
                }
                // }
            }
            conn.commit();
            stmt.close();
        }    public TableInstance(InterfaceEPC epc, Vector c, TableInstance tk, int k)
                throws SQLException {
            // get max used serial number
            int start = DbTools.getTableStartId();
            // ---end of get max used serial number        // print c
            /*
             * System.out
             * .println("=====================================================");
             * System.out.println("k=" + k); for (int h = 0; h < c.size(); h++) {
             * Vector hhh = (Vector) c.elementAt(h);
             * System.out.println(hhh.toString()); } System.out
             * .println("=====================================================");
             */
            // ---end print c
            Connection conn = null;
            Statement stmt = null;
            //conn.setAutoCommit(false);        for (int i = 0; i < c.size(); i++) {
                conn = DBConnection.getConnection();
                stmt = conn.createStatement();
                conn.setAutoCommit(false);
                Vector types = (Vector) c.elementAt(i);
                // System.out.println("k=" + k + ",types=" + types.toString());
                Collections.sort(types); // sort types by type name
                String typeStr = Rule.vectorToString(types); // typeStr used to
                // get table name
                int tblId = start + i + 1; // get a table serial number
                String tblName = "T" + tblId; // generate a new table name
                StringBuffer sql = new StringBuffer(); // create table sql
                StringBuffer sql2 = new StringBuffer(); // create index sql
                sql.append("CREATE TABLE ").append(tblName).append(" (");
                sql2.append("CREATE UNIQUE INDEX IDX_").append(tblName).append(
                        " ON ").append(tblName).append("(");
                System.out.println("--->types=" + types.toString());
                // use all type as column name
                for (int j = 0; j < k + 1; j++) {
                    String type = (String) types.elementAt(j);
                    //System.out.println("--->type=" + type + ", j=" + j);
                    sql.append(type).append(" INTEGER, ");
                    sql2.append(type).append(",");
                }
                sql.append(" ID INTEGER)");
                String sql2Str = sql2.toString();
      

  2.   

    http://www.blogjava.net/aixy/articles/14992.html