public boolean copy(String whereClause,boolean dropFirst){
  log.info(whereClause);
  if (getConnection(false,true) == null)   return false;
  boolean success=true;
  int count=0;
  ArrayList<String> list=new ArrayList<String>();
  String sql="SELECT * FROM AD_Table";
  if (whereClause != null && whereClause.length() > 0)   sql+=" WHERE " + whereClause;
  sql+=" ORDER BY TableName";
  PreparedStatement pstmt=null;
  ResultSet rs=null;
  try {
    pstmt=DB.prepareStatement(sql,null);
    Connection conn=pstmt.getConnection();
    DatabaseMetaData md=null;
    if (conn != null)     md=conn.getMetaData();
 else {
      throw new DBException("No Connection");
    }
    rs=pstmt.executeQuery();
    while (rs.next() && success) {
      MTable table=new MTable(m_ctx,rs,null);
      if (table.isView())       continue;
      if (dropFirst) {
        executeCommands(new String[]{"DROP TABLE " + table.getTableName()},m_conn,false,false);
      }
      if (createTable(table,md)) {
        list.add(table.getTableName());
        count++;
      }
 else       success=false;
    }
  }
 catch (  Exception e) {
    log.log(Level.SEVERE,sql,e);
    success=false;
  }
 finally {
    DB.close(rs,pstmt);
    rs=null;
    pstmt=null;
  }
  if (!success)   return false;
  enableConstraints(list);
  databaseBuild();
  log.info("#" + count);
  try {
    if (m_conn != null)     m_conn.close();
  }
 catch (  SQLException e2) {
    log.log(Level.SEVERE,"close connection",e2);
  }
  m_conn=null;
  return success;
}

public boolean copy ( String whereClause , boolean dropFirst ) { log . info ( whereClause ) ; if ( getConnection ( false , true ) == null ) return false ; boolean success = true ; int count = 0 ; ArrayList < String > list = new ArrayList < String > ( ) ; String sql = "SELECT * FROM AD_Table" ; if ( whereClause != null && whereClause . length ( ) > 0 ) sql += " WHERE " + whereClause ; sql += " ORDER BY TableName" ; PreparedStatement pstmt = null ; ResultSet rs = null ; try { pstmt = DB . prepareStatement ( sql , null ) ; Connection conn = pstmt . getConnection ( ) ; DatabaseMetaData md = null ; if ( conn != null ) md = conn . getMetaData ( ) ; else { throw new DBException ( "No Connection" ) ; } rs = pstmt . executeQuery ( ) ; while ( rs . next ( ) && success ) { MTable table = new MTable ( m_ctx , rs , null ) ; if ( table . isView ( ) ) continue ; if ( dropFirst ) { executeCommands ( new String [ ] { "DROP TABLE " + table . getTableName ( ) } , m_conn , false , false ) ; } if ( createTable ( table , md ) ) { list . add ( table . getTableName ( ) ) ; count ++ ; } else success = false ; } } catch ( Exception e ) { log . log ( Level . SEVERE , sql , e ) ; success = false ; } finally { DB . close ( rs , pstmt ) ; rs = null ; pstmt = null ; } if ( ! success ) return false ; enableConstraints ( list ) ; databaseBuild ( ) ; log . info ( "#" + count ) ; try { if ( m_conn != null ) m_conn . close ( ) ; } catch ( SQLException e2 ) { log . log ( Level . SEVERE , "close connection" , e2 ) ; } m_conn = null ; return success ; }
create tables and copy data
