package examples.dbkona;
import weblogic.db.jdbc.*;
import weblogic.db.jdbc.oracle.*;
import java.sql.*;
import java.util.Properties;
/**
* This class demonstrates using a dbKona Sequence object to create,
* use, and drop an Oracle sequence. A dbKona Sequence object is a
* wrapper for an Oracle sequence.
*
* To run this example, you'll need an Oracle database. The example
* is executed from the command line and results are displayed to
* standard out.
*
To set up this example:
*
*- Set up your development shell as described in
*Setting up your environment.
*
*
- Change connection parameters to correspond to your Oracle configuration.
* If you need more help, check the section on connecting
*to a database in the Developers Guide, Using WebLogic jDriver for Oracle.
*
*
*
- Compile this example by executing the following command in your development shell:
*
*
*
*$ javac -d %CLIENT_CLASSES% sequences.java
*
*
*
- Run this example by executing the following command in your development shell:
*
*
*
*$ java examples.dbkona.sequences
*
*
*
* @author Copyright (c) 1996-2000 by BEA Systems, Inc. All Rights Reserved.
*/
public class sequences {
/**
* Here the JDBC connection is configured and made. Before we
* attempt to create a new dbKona Sequence, which is always
* used in context of the JDBC connection object, we first try
* to drop a Sequence of the same name. Then the Sequence is
* created and its next value is printed out in a loop from
* 0 - 9. Finally the Sequence is dropped and closed, and the
* JDBC connection is closed.
*/
public static void main(String argv[]) {
Connection conn = null;
Sequence seq = null;
try {
// For more information on making a connection, see the
// dbKona Developers Guide.
Class.forName("weblogic.jdbc.oci.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:weblogic:oracle:DEMO",
"scott",
"tiger");
// Drop the sequence from the server if it already exists.
try {Sequence.drop(conn, "testseq");} catch (Exception e) {;}
// Create a new sequence on the server. The first integer argument
// is the increment, the second is the starting value.
Sequence.create(conn, "testseq", 1, 1);
seq = new Sequence(conn, "testseq");
// Print out the next value in the sequence in a loop.
for (int i = 0; i < 10; i++) {
System.out.println(seq.nextValue());
}
System.out.println(seq.currentValue());
} catch(Exception e) {
System.err.println("Trouble while executing example");
e.printStackTrace();
} finally {
// You should always close DataSets, ResultSets, and Statements
// when you have finished working with them.
try {
seq.close();
} catch (Exception e) {}
// Drop the sequence from the server.
try {
Sequence.drop(conn, "testseq");
} catch (Exception e) {
System.err.println("Trouble removing sequence from DBMS");
e.printStackTrace();
}
// Finally, close the connections.
try {
conn.close();
} catch(Exception e) {}
}
}
}