Read one record at a time

Hi !
One of our Java folks here need at function where he reads one record at at time in id order;
create table url_recs (id number, url varchar2(4000));
insert into url_recs values(1,'www.fona.dk');
insert into url_recs values(2,'www.dr.dk');
insert into url-recs values(17,'www.ihk.dk');
select read_rec() from dual; - get id 1
select read_rec() from dual; - get id 2
select read_rec() from dual; - get id 17
select read_rec() from dual; - get id 1 - "no more rows - start all over again)
select read_rec(45) from dual; - get NULL (no rows with that id)
select read_rec(1) from dual; - get id 1
The purpose id for some "round robin" trying to get to some internal URL's.
Can you give me a hint for creating the function(s)
best regards
Mette

Will successive calls come on the same Oracle session? Or across different Oracle sessions?
If you're going to call the function multiple times within the same Oracle session, you could store the last value returned in a package variable and select the record whose ID is greater than that value every time the function is called. That's unlikely to do exactly what the Java developer is hoping, though, because the Java calls are likely to bounce between multiple Oracle sessions due to connection pooling. And it'll likely require that the Java developer (or app server admin) adds some code when they get a connection from the pool where they reset the package state. Or it'll require that someone develop a method to keep the Java and Oracle session state in sync.
Justin

Similar Messages

  • Challenge involving creating a file on GUI & seeing one record at a time...

    Hi,
    If anyone can help me with this project I'd be most appreciative. I'll try and explain the problem the best I can. I'm adding students to a database at a university they're either a Graduate or an Undergraduate. I'm taking in first, lastname's, ssn, & ACT/SAT/GMAT test results. I have a GUI called StudentRecord that has all the JTextFields, JButton's, etc. I'm also writing it to a .txt file called StudentDA. For this I used a BufferedFile reader.
    What I really need is on my StudentRecord when I click the display button I want it to show one record at a time in another JFrame. This other JFrame I named it display. I'm trying to create an instance of JFrame inside of the actionPerformed for StudentRecord but when I click display nothing happens.
    I adding the students with a vector that I'm calling v. I want the Display to read from the .txt file and display one at a time hence next, and previous. I'm going to post the tidbit of relevant code. If anyone can help me you'd be my hero for the day for all time I've tried to get this to work.
    Here's the StudentRecord (GUI) display part:
          public void actionPerformed( ActionEvent event )
         try {
              Display d = new Display(StudentDA.v);
             }//end try
            //catch right here no problems with this..Here's the DataAccess part:
    public class StudentDA{
      static Vector v = new Vector();;
      static String pathName = "a:/Final Project/test1.txt";
      static File studentFile = new File(pathName);
      static String status;
      public StudentDA() {}
      public static void initialize() {
        if (studentFile.exists() && studentFile.length() !=0) {
         try{
          BufferedReader in = new BufferedReader(new
          FileReader(studentFile) );
          do{
             status = in.readLine();
              if(status.equals ("uGrad")) {
                uGrad u = new uGrad();
                u.setFName(in.readLine() );
                u.setLName(in.readLine() );
                u.setssNum(Integer.parseInt(in.readLine()) );
                u.setACT(Integer.parseInt(in.readLine() ));
                v.add(u);
                System.out.println(u + "inside ugrad");
              }//end if uGrad
              else{
                if(status.equals("Grad")) {
                //same process as uGrad
                v.add(g);
              }//end else Grad
          }while (status != null);
        }//end try statement
        catch (Exception e) {
          }//end catch
        }//end if there's something there
      }//end method initialize
      //creating the terminate method
      public static void terminate() {
        try{
          PrintStream out = new PrintStream ( new
          FileOutputStream (studentFile) );
          for (int i = 0; i < v.size(); i++) {
            Student s = (Student) v.elementAt(i);
            String p = s.printRecord();
            StringTokenizer rt = new StringTokenizer(p, "\t");
            while (rt.hasMoreTokens() ) {
              out.println(rt.nextToken() );
              }//end while
          }//end for loop
        }//end try loop
        catch (Exception e){
        }//end catch
      }//end terminate
    public static void add(Student s){// throws DuplicateException{
              boolean duplicate = false;
              for(int i = 0; i < v.size(); i++){
                   if(s.getssNum() == ((Student)(v.elementAt(i))).getssNum()){
                        duplicate = true;
                        break;
                   if(duplicate){
                        throw new DuplicateException("Student Already Exists");
                   else{
                        v.add(s);
    }//end add method
    }//end classHere's the display class:
    public class Display extends JFrame {
         private JButton Next, Previous;
         private JTextField statusField, firstField, lastField, socialField, advPlacementField, actField;
         private JLabel statusLabel, firstLabel, lastLabel, socialLabel, advPlacementLabel, actLabel;
         private JPanel fieldPanel, buttonsPanel;
         private JTextArea displayArea;
         static int count = 0;
         static String status;
         public Display(){}
    public Display(Vector v){
         //setting up the GUI components for the display class here
         //JTextAreas & JLabels
         buttonsPanel = new JPanel();
         buttonsPanel.setLayout(new GridLayout(1,2));
        Next = new JButton("Next");
        buttonsPanel.add(Next);
        Next.addActionListener(
        new ActionListener() {
          public void actionPerformed( ActionEvent event )
              //try to catch display errors
           try {
                        count++;
                     displayData(count);
                     //displayData();
          }//end try
              catch {
             }//end catch
          } // end actionPerformed
        } // end anonymous inner class
        ); // end call to addActionListener
        buttonsPanel.add(Next);
        Previous = new JButton("Previous");
        buttonsPanel.add(Previous);
        Previous.addActionListener(
        new ActionListener() {
          public void actionPerformed( ActionEvent event )
              //try to catch display errors
              try {
                   count--;
                   displayData(count);
                   //displayData();
             }//end try
              catch {
             }//end catch
          } // end actionPerformed
        } // end anonymous inner class
        ); // end call to addActionListener
    }//end display() constructor
    public void displayData(int count) {
         StudentDA.initialize();
           if (status.equals ("uGrad")) {
           //these are all part of the StudentRecord GUI not Display GUI
                fieldPanel.setVisible(true);
                buttonsPanel.setVisible(true);
                actLabel.setVisible(true);
                actField.setVisible(true);
                advPlacementLabel.setVisible(false);
                advPlacementLabel.setVisible(false);
           }//end if
           else {
                if(status.equals ("Grad")) {
                 fieldPanel.setVisible(true);
                 buttonsPanel.setVisible(true);
                 actLabel.setVisible(false);
                 actField.setVisible(false);
                 advPlacementLabel.setVisible(true);
                 advPlacementLabel.setVisible(true);
                  }//end if
           }//end else
    }//end method displayData()
    public static void main ( String args[] )
        Display application = new Display();
        application.addWindowListener(
              new WindowAdapter(){
                   public void windowClosing( WindowEvent e)
                        System.exit(0);
        application.setSize( 300, 200);
        application.setVisible( true );
    };//end main
    }//end class Display{}I know this is long but if anyone can help I'd greatly appreciate it. Please ask me if you need me to clarify something, I tried to not make it way too long. --rockbottom01
         

    I'm not really too sure what it is that you are after, but here is some code, that loads up an array with each line of a .txt file, then displays them. I hope you can make use of a least some of it.
    just ask if you don't understand any of the code.
    String array[];
    int i;
    public Test() {
              readFile("file.txt");
              i = 0;
              nextEntry();
         public void nextEntry() {
              Display display = new Display();
              display.show();
         class Display extends JFrame implements ActionListener {
              JLabel label1;
              JButton button;
              public Display() {
                   label1 = new JLabel(array);
                   button = new JButton("OK");
                   getContentPane().setLayout(new FlowLayout());
                   getContentPane().add(label1);
                   getContentPane().add(button);
                   button.addActionListener(this);
              public void actionPerformed(ActionEvent e) {
                   setVisible(false);
                   i++;
                   if(i < array.length) {
                        nextEntry();
         public void readFile(String fileName) {
              String s, s2 = "";
              int lineCount = 0;
              BufferedReader in;
              try {
                   in = new BufferedReader(new FileReader(fileName));
                   while((s = in.readLine()) != null) {
                        lineCount++;
                   array = new String[lineCount];
                   in.close();
                   in = new BufferedReader(new FileReader(fileName));
                   int j = 0;
                   while((s = in.readLine()) != null) {
                        array[j] = s;
                        j++;
              catch(IOException e) {
                   System.out.println("Error");

  • Return only one record at a time

    I am new to crystal reports so any help would be appreciated.  I have a .net app that is a order processing system.  When the user is in a record, they want to be able to click on a button an open a crystal report showing only that orders details.  I created a crystal report that has the following fields:
    Order ID, Product ID, Unit Price, Sell Price, Hours.
    The Order ID is the primary key in the database.  The report runs fine when clicking the report button in the app, but returns the details for every order in the database.  We just need the details of the order that the user is processing.  How do I setup the report to only show that order's details?  I am using VB 2005 and Crystal v9.
    Edited by: sking on Mar 6, 2009 1:12 AM

    Brian,
    Thank you for all your help.  I have been able to setup the report to return only one record at a time. In my app, when I click the report button the PDF opens perfectly with only one record.  However, when I go to another record and open the PDF it returns the information from the record id that was set as the default parameter value (crReportDocument.SetParameterValue("Orders", 67).  How do I get it to return the report for a different record?  Here is the code I'm using.  I think I'm really close with your suggestions but I'm just missing one step. 
    #Region "CrystalReport"
         ''' <summary>
         '''Override the CrystalReportButton_Click and call DisplayReportAsPDF_CrystalReportButton function
         ''' </summary>
         Public Sub CrystalReportButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
          Dim crReportDocument As CrystalDecisions.CrystalReports.Engine.ReportDocument = New CrystalDecisions.CrystalReports.Engine.ReportDocument
          Dim fileName As String = "test.rpt"
          Try
              If fileName.Substring(1).StartsWith(":\") Then
              crReportDocument.Load(fileName)
          Else
              crReportDocument.Load(Me.Page.MapPath(fileName))
          End If
          Catch ex As Exception
              Dim errMsg As String = ex.Message.Replace(Chr(13).ToString(), "").Replace(Chr(10).ToString(), "")
              errMsg += " Please make sure the dlls for Crystal Report are compatible with the Crystal Report file."
              BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(Me, "BUTTON_CLICK_MESSAGE", errMsg)
          End Try
          Try
    Dim paramValue As CrystalDecisions.Shared.ParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue()
               paramValue.Value = "67"
               crReportDocument.SetParameterValue("Orders", 67)
    DisplayReportAsPDF_CrystalReportButton(crReportDocument)
          Catch ex As Exception
              Dim errMsg As String = ex.Message.Replace(Chr(13).ToString(), "").Replace(Chr(10).ToString(), "")
              errMsg += " If this is a deployment machine, make sure network service has permissions to read or write to the windows\temp folder."
              BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(Me, "BUTTON_CLICK_MESSAGE", errMsg)
          End Try

  • Master_detail for more than one record at a time

    Hi,
    How can i display master_detail records for more than one records at a time, for example, i have two tables A and B , A has username and role and B has username and profile. here i wanted to display 10 users at a time on my 6i form with username, role and profile.
    i have created a master-detail relation ship with these tables when i'm executing F8 on blcok A , it displays 10 records on BlockA but, only one at a time on block B, how can i display all corresponding records on block B at a time.
    Thanks for your help.Bcj

    Thanks Roberts, that was realy informative due to some doubts i would like to confirm my requirements , i have two blocks A and B and each master record has only one detail record. but i wanted to display at least 10 master_detail relationships(records) on the form at a time, i would like to know is it possible to do without creating any table or view for example,
    data in table A,
    username role
    AAA R1
    BBB R2
    CCC R3
    data in table B,
    username profile
    AAA P1
    BBB P2
    CCC P3
    i wanted to display it on form like below,
    username role profile
    AAA R1 P1
    BBB R2 P2
    CCC R3 P3
    Also would like to know that how can i select data from dba_users, any restriction is there on forms 6i, i can select it on sqlplus.
    Thanks Again, Bcj

  • How to select only one record at a time in ALV

    Hi all,
    I have to use ALV report.  Each record on the report output should have a button (or radio button) which will allow the record to be selected.  My requirement is to select only one record at a time.
    please guide me how to proceed further.
    regards
    manish

    hi
    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/sampleCheckBoxProgram
    Regards
    Pavan

  • How to delete one record at a time

    hi all,
    Please tell me how i do delete only one record at a time.After deleting the record the jsp page should show only the remining items to be deleted.

    Where do u want to delete the record - database?
    If so use the rpimary Screen identifying each record and use that to delet that record

  • Pass one record at a time

    how can i pass one record at a time from a sub report to the main report by evaluating if it exists in the main report?

    You should be posting in the advanced queuing forum.
    Advanced Queueing

  • Read one word at a time from a text file

    I want to read one word at a time from a text file as it is done by "scanf &s" function in text based programme. It is not possible by " read from text"  function. Suggest me  function or method to solve this.

    The simplest way is to use the spreadsheet string to array function with the space character as the delimiter.
    Note that this won't work unless there is a space character between the words - it won't work with line feeds / carriage returns between the words but you could always split the string into lines first. You may also want to trim whitespace to remove any other non-visible characters (e.g. tab, line feeds) from around the word.
    If you need something more sophisticated that splits based on whitespace (e.g. tab, new line) then you'll probably need to do something with searching the string for these characters (e.g. using a regular expression) and then splitting them yourself into an array.
    Of course...if you actually want to just read one word at a time from the file rather than just split the file into words (I assumed you meant this), you will need to read the file byte by byte using the low level file IO functions, build a buffer of the bytes and check the character you've read to see if it a space.
    Certified LabVIEW Architect, Certified TestStand Developer
    NI Days (and A&DF): 2010, 2011, 2013, 2014
    NI Week: 2012, 2014
    Knowledgeable in all things Giant Tetris and WebSockets

  • Reading one character at a time

    Hello
    How can i read one character at a time from standard input (System.in) ?
    I have tried to use
    ir=new InputStreamReader(System.in)
    ir.read().
    But this method blocks until it gets a return key pressed before going forward
    Any other solution?

    public static char readChar() {
    int ch;
    char r = '\0';
    boolean done = false;
    while (!done) {
    try {
    ch = System.in.read();
    r = (char) ch;
    if (r == '\r') {
    System.out.println("Not a character. Please try again!");
    System.in.skip(1);
    done = false;
    } else {
    System.in.skip(2);
    done = true;
    } catch (java.io.IOException e) {
    done = true;
    return r;
    Try this as an method and then use it..
    This code will read will be in response untill you hit the return key but will take only the first character....

  • Reading one file at a time using File Adapter

    I am using a File Adapter which polls every minute to read files from a Folder. This process picks up all the files in that folder. What I want to achieve is that the File Adapter should read one file at a time. Is it possible to force it to wait for a few seconds before reading the Next file in the Folder. Or is there a solution to what I am trying to achieve? Any help would be appreciated.

    public static char readChar() {
    int ch;
    char r = '\0';
    boolean done = false;
    while (!done) {
    try {
    ch = System.in.read();
    r = (char) ch;
    if (r == '\r') {
    System.out.println("Not a character. Please try again!");
    System.in.skip(1);
    done = false;
    } else {
    System.in.skip(2);
    done = true;
    } catch (java.io.IOException e) {
    done = true;
    return r;
    Try this as an method and then use it..
    This code will read will be in response untill you hit the return key but will take only the first character....

  • XML import only creates one record at a time

    Hi All,
    I have an XML import map that automatically imports data into main product table. It's working fine when the XML file has only one main record. When it has more than one record, the import manager and import server can only import the last record in the file and skip the rest.
    I already checked the record matching tab. It correctly shows that all records will be created and 0 will be skipped. Even the log file indicates all records are created after I execute the map. Yet, when I try to look for them in the data manager, I can only find the last one. If I execute the map with the exact same file again, it will create one more record again and skip the rest.
    Someone else posted the same question a while back: Import map issue one record at a time. But it was never answered. Does anyone else have this issue? Is this a MDM bug?
    Thanks,
    Kenny

    Hi Kenny,
    Please refer to the note below:
    Note 1575981
    Regards,
    Neethu Joy

  • Import map issue one record at a time

    Hello Experts,
    I built an import map to run it manually with import manager, but when I click on Ready to Import, the import manager is doing one record at a time.  I have to go back to the match tab and refresh in order to import the rest. 
    Any idea where to setup a setting to import all records at once?
    Thank you very much for your help,
    Claudia Hardeman

    Hi Claudia,
    Please check if your matching criteria results in fewer records,what is the matching criteria you are setting?
    Do you see a total of 300 under "Create" Match Action?
    No of records to be imported is governed by Match action which tell the MDS which are distinct records,Match Action tells MDS what is to be done with this number of records which have this Match type.
    Please check if you have "SKIP" as match action,if yes use a appropriate action for match type.
    Do a "Save Update" of the map.
    Please revert with results.
    Thanks,
    Ravi

  • XSU: Reading each record at a time

    I am using XSU12 to retrieve database contents in XML format. I am passing the Connection and ResultSet objects to create OracleXMLQuery object. I want to read each record at a time and so setting the maxRows to 1 and then getting the xmlstring.
    code looks like...
    qry =new OracleXMLQuery(connection,resultset);
    qry.setMaxRows(1);
    xmlString = qry.getXMLString();
    I keep this in a loop and read each record at a time. The problem is whenever getXMLString() method is called, the application is hitting the database, which will be a performance issue.
    Is there any way to read contents of a table at once and then loop each record at a time without hitting the DB everytime?
    Kishore
    null

    public static char readChar() {
    int ch;
    char r = '\0';
    boolean done = false;
    while (!done) {
    try {
    ch = System.in.read();
    r = (char) ch;
    if (r == '\r') {
    System.out.println("Not a character. Please try again!");
    System.in.skip(1);
    done = false;
    } else {
    System.in.skip(2);
    done = true;
    } catch (java.io.IOException e) {
    done = true;
    return r;
    Try this as an method and then use it..
    This code will read will be in response untill you hit the return key but will take only the first character....

  • Displaying one record at a time

    Is any body able to help me? I need to display one record at a time from a Select statement.
    Could I copy the results of the Select query from a table into an array for later display or is there a better alternative.
    Please, any part knowledge with regard to the above would be usefull.
    Regards
    Eddie

    What application do you want to use to display the data?
    You can use "rownum" in your SQL statement to ensure that you only get record N of a query. Asktom has a good article on this sort of windowing
    http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:127412348064
    More commonly, however, you'll write a SQL query that returns all the rows, fetch a small number, display those to the user, and then fetch more records.
    Justin

  • How to read one bye at a time

    i need to read one byte at a time from a input file. can someone tell me how to do that?

    FileInputStream istream = new FileInputStream(myFile);
    int read_byte = istream.read();API doc work wonders on issues like that

Maybe you are looking for

  • Failed to Retrieve SQL

    Hi, Using STANDARD REPORT CREATION WIZARD, I connected to UNIVERSES Data Sources and RUN a querry in BUSINESS OBJECTS QUERY PANEL,i am getting ERROR Message "Failed to Retrieve SQL".What would be the causes? Thanks, Sandeep

  • HT201365 how to unlock my ipod when i cant remember my pass code

    i cant remeber my pass code and my ipod wont unlock

  • No thumbnails after burning photo's

    Dealing with a very strange issue.  A customer is running a new MBP 10.6.8 ilife 11 full updated.  She burns a set of photo's which burn fine but when she tries to view them the thumbnails are missing.  The strange thing is that when you double click

  • IS IT OK TO CONNECT IPOD TO MACBOOK IN ITALY W/O A CONVERTER?

    I just arrived in Italy and plugged my iPod to my Macbook, which was plugged (without a converter, of course) to a wall outlet. My iPod froze, showing just the "Do Not Disconnect" sign. Help! Did I do something wrong? Shouldn't I connect without a co

  • Formvalidation conditional on checkbox

    I have a form (payment) where users enter creditcard information. All fields are required. Except Some users may choose to have their credit card information collected by phone. In that case, they check a Checkbox (input name="Later" type="checkbox"