import java.sql.Connection;   import java.sql.DriverManager;
import java.sql.ResultSet;    import java.sql.SQLException;   import java.sql.Statement;
public class JdbcSequence {
 public static void main(String[] args){
  try { // sequence only allowed with postgres!
   Connection con = DriverManager.getConnection("jdbc:postgresql://localhost:5432/thedb", "user", "passwd");
   String sql = "CREATE TABLE test AS SELECT * FROM continent; " +
                "DELETE FROM test; DROP TABLE test; " +
                "SELECT * FROM country;";
   Statement stmt = con.createStatement();
   boolean hasMoreResultSets = stmt.execute(sql);
   while ( hasMoreResultSets || stmt.getUpdateCount() != -1 ) {
     if ( hasMoreResultSets ) { // if has rs
         ResultSet rs = stmt.getResultSet();
         int size = 0; while (rs.next()) { size++; }
         System.out.println("Result set size: " + size); }
     else { // if ddl/dml/...
       int queryResult = stmt.getUpdateCount();
       System.out.println(queryResult + " tuples updated");
     } // check whether to continue in the loop:
     hasMoreResultSets = stmt.getMoreResults();
   } // while results
   stmt.close(); con.close();
  } catch (SQLException e) { e.printStackTrace(); } } }
