Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.tools -> Re: How do you retrive the CURRVAL of the sequence from a servlet?

Re: How do you retrive the CURRVAL of the sequence from a servlet?

From: Bob Fazio <rfazio_at_home.com.nospam>
Date: 2000/05/04
Message-ID: <fdhQ4.171015$Tn4.1263409@news1.rdc2.pa.home.com>#1/1

If he doesn't know the answer he won't get the comment.

You can't call currval until you have already called nextval in a session. With JDBC you need to create a statement.

This should help.

import java.sql.*;
import java.math.*;

/*
/**

*
  /**
   * @param args the command line arguments
   */

  public static void main (String args[]) throws SQLException {     // Load Oracle driver
    DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());

    // Connect to the local database
    Connection conn =
    DriverManager.getConnection
("jdbc:oracle:thin:@"+args[0]+":1521:"+args[1], "system", "manager");

    PreparedStatement stmtUsers = conn.prepareStatement("select username from all_users");

    PreparedStatement stmt = conn.prepareStatement ("select count(*) from dba_segments where owner = ? ");
// just replace one of the above statements with your select from the sequence.

    ResultSet rusers = stmtUsers.executeQuery();     ResultSet rset;

    while(rusers.next())
    {

      stmt.setString(1,rusers.getString(1));
      rset = stmt.executeQuery();

      while (rset.next ())
      System.out.println ( rusers.getString(1) + " Objects:" +
rset.getString (1));

    }
  }  

}

--
Robert Fazio, Oracle DBA
rfazio_at_home.com
remove nospam from reply address
http://24.8.218.197/
"Sybrand Bakker" <postbus_at_sybrandb.demon.nl> wrote in message
news:957453228.29840.0.pluto.d4ee154e_at_news.demon.nl...
> Answers embedded
>
> Hth,
>
> Sybrand Bakker, Oracle DBA
>
> Yi Jin <yijin_at_wam.umd.edu> schreef in berichtnieuws
> 8es2j8$ovv_at_rac2.wam.umd.edu...
> >
> > I need to put the current value of a sequqnce in a text field in a
> > servlet. How do you retrive it from JDBC?
> >
> > Do I have to invoke nextval before retrive currval?
>
> Yes
>
> What is the best
> > way to retrive the currval without invoke nextval?
>
> You can't
> >
> > The column is either generated from the sequence, or manuall entered.
> >
> > Thanks.
> >
> > YJ
>
>
Received on Thu May 04 2000 - 00:00:00 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US