Vectors -please explain

I'm looking through a textbook (Java How to program by Dietel abd Dietel) which provides some code to connect to database and then to display the database on the screen. However, I am trying to understand the code and can't understand the following methods.
From what i can see currentRow is a vector within a set of other vectors; rows. Am I right? Basically I just want to know how the vectors in this code extract work. Thanks.
private void displayResultSet(ResultSet rs)throws SQLException{
       boolean moreRecords = rs.next(); //position to first records
//       If there are no records, display a message
          if (! moreRecords){
               JOptionPane.showMessageDialog (this, "The specified table contains no"
                                                     + " records");
               setTitle ("No records to display");
               return;
          Vector columnHeads = new Vector ();
          Vector rows = new Vector();
          try{
//       get column heads
               ResultSetMetaData rsmd = rs.getMetaData();
               theCount = rsmd.getColumnCount();
               dist.setUp(theCount, theRowCount);
               for (int i = 1; i <= rsmd.getColumnCount(); ++i)
                    columnHeads.addElement(rsmd.getColumnName(i));
                    do{
                         rCount++;
                         rows.addElement(getNextRow(rs, rsmd));
                    } while (rs.next());
               JTable thetable = new JTable (rows, columnHeads);
               JScrollPane scroller = new JScrollPane(thetable);
                getContentPane().add(scroller, BorderLayout.CENTER);
               validate();
                 dist.doComparison(columnHeads, rows);
     catch (SQLException e){
       //display some message
  private Vector getNextRow(ResultSet rs, ResultSetMetaData rsmd)
       throws SQLException{
   Vector currentRow = new Vector();
     for (int i=1; i <= rsmd.getColumnCount(); ++i)
          switch (rsmd.getColumnType(i)){
               case Types.VARCHAR:currentRow.addElement(rs.getString(i));
                    break;
               case Types.INTEGER:currentRow.addElement(new Long (rs.getLong (i)));
                    break;
               default:
                    System.out.println("Type was: " + rsmd.getColumnTypeName (i));
     return currentRow;
  }

Did D&D tell you to put this code in?
     catch (SQLException e){
     //display some message
     }Terrible idea. At LEAST print the stack trace:
catch (Exception e)
    e.printStackTrace();
}An empty catch block is a great way to have a class that fails "mysteriously" with no feedback or info. You'll debug for a long time until you add that stack trace print.
I've heard that D&D puts out good books, but if they're recommending that you code this way I'd throw it out.
If you did that on your own, give yourself a d0pe slap and add the stack trace from now on. - MOD

Similar Messages

  • Could Somebody Please Explain....

    Could somebody please explain what this section of code is doing with the StopTime? There is plenty more code where that came from, but as I can see it, it is being put into a vector in another section of code as endTime, the vector pdmlist, which I think is where or hows its stored in the vector is being set to null? Then pdmlist is using EndTime value? The StopTime is then being set to a string.
    StopTime is then set to blank, then the DateDataFormat is being used. The pdmlist comes back into play, then the df (date format) comes back and it gets converted to uppercase and finally outputted using the outStream.write method to the log file that is created (earlier).
    So my quest, as per the other mail, why wont the DB query and order by, order it for the output to the log file. What is the vector doing to it to unsort it? How can I order it?
    Vector pdmList = null;
    this.setCursor( Cursor.WAIT );
    if ( radioAllTime.getChecked() )
    pdmList = pdmHelper.buildPDMList( ctx, null, null );
    else
    pdmList = pdmHelper.buildPDMList( ctx, dateBeginTime.getValue(), dateEndTime.getValue() );
              this.setCursor( Cursor.DEFAULT );
    //If nothing was found, then display a message,
              //and return.
              if ( pdmList == null )
                   MessageBox.show( "No parametric data found. Log file not generated." , this.getText() );
                   return;
    if ( pdmList.size() == 0 )
                   MessageBox.show( "No parametric data found. Log file not generated." , this.getText() );
                   return;
              String Temp;
    String Board; // Prodid
    String StartTime;
    String StopTime;
    String Part;
    String BoardStatus;
    String Actual;
    String LoLim;
    String HiLim;
    String MeasStatus;
    String PartType;
    String PartNumber;
    boolean BoardStatusContext = false;
    boolean OneMeasureFailed = false;
    java.util.Hashtable htFiles = new Hashtable(10,10);
    FileWriter outStream = null;
    try
    for ( int idx = 0; idx < pdmList.size(); idx++ )
                        //Reset the flags
                        BoardStatusContext = false;
                        OneMeasureFailed = false;
    Board = ""; StartTime = ""; StopTime = ""; Part = ""; BoardStatus = ""; Actual = "";
    LoLim = ""; HiLim = ""; MeasStatus = ""; PartType = ""; PartNumber = "";
    com.ms.wfc.data.DateDataFormat df = new com.ms.wfc.data.DateDataFormat( com.ms.wfc.data.DateFormat.CUSTOM,
    "dd-MMM-yy hh:mm:ss" );
    // get root context
    PDMContext context = ((PDM)pdmList.elementAt(idx)).getContext();
    //Make the filename
    String fileName = context.getProductName();
    if ( fileName == null || fileName.length() == 0 )
    fileName = "UNKNOWN";
    // Eliminate not allowed characters from the file name
    fileName = fileName.replace('\\','_');
    fileName = fileName.replace('/','_');
    fileName = fileName.replace(':','_');
    fileName = fileName.replace('*','_');
    fileName = fileName.replace('?','_');
    fileName = fileName.replace('\"','_');
    fileName = fileName.replace('<','_');
    fileName = fileName.replace('>','_');
    fileName = fileName.replace('|','_');
    fileName += ".log";
    if ( htFiles.containsKey( fileName ) )
    outStream = (FileWriter)htFiles.get( fileName );
    else
    File theFile = new File( fileName );
    statusBar.getPanels()[0].setText( "File: " + theFile.getAbsolutePath() );
    /* if ( ! theFile.canWrite() )
    statusBar.getPanels()[0].setText( "Failed: " + theFile.getAbsolutePath() );
    MessageBox.show( theFile.getAbsolutePath() + " can not be writen!",
    this.getText() );
    outStream = new FileWriter( theFile.getAbsolutePath(), false );
    htFiles.put( fileName, outStream );
    // start writing the log file...
    outStream.write( "./" );
    StartTime = ((String)df.format( null, context.getStartTime() )).toUpperCase();
    StopTime = ((String)df.format( null, context.getStopTime() )).toUpperCase();
    Board = context.getProductName();
    if ( Board.length() == 0 )
    Board = "UNKNOWN";
    outStream.write( Board + ".obc[" + StartTime + "\r\n\r\n" );
    Sorry the mail is so long. I tried books, but vectors were hard to come by? I've searched through the database on this site too, there are plenty of stuff about sorting and vectors but its hard to use somebody elsed situation for my own circumstances as a guide.
    Hope somebody could just shed a bit of light.
    Thanks in advance.
    Mark.
    PS. I will give duke points (when I work out how to add them, but I only have 5....sorry)

    Does anybody have any ideas as to what is happening.
    Mark.

  • In our enterprise MPLS network we are using 192.168.20.0/24 subnet, in this subnet we have not assigned the IP 192.168.20.200/30 & 204/30, But still these subnets are reachable . Are these NNI IP ...Please explain.

    In our enterprise MPLS network we are using 192.168.20.0/24 subnet, in this subnet we have not assigned the IP 192.168.20.200/30 & 204/30, But still these subnets are reachable . Are these NNI IP ...Please explain.

    I have checked with ISP, there response is like below:
    Those are the NNI to GBNET IPs for Dominican Republic. They are Network IPs. You should be able to ping them-that means they are working.
    WANRT01#show  ip route | include 192.168.20.20
    B        192.168.20.200/30 [20/0] via 192.168.20.226, 02:18:29
    B        192.168.20.204/30 [20/0] via 192.168.20.226, 02:18:29
    Here its shows from any of our MPLS site we are able to trace the IP and it seems like, 192.168.20.204/30 is one more site but in actual its not.
    INMUMWANRT01#ping 192.168.20.205
    Type escape sequence to abort.
    Sending 5, 100-byte ICMP Echos to 192.168.20.205, timeout is 2 seconds:
    Success rate is 100 percent (5/5), round-trip min/avg/max = 224/232/260 ms
    INMUMWANRT01#trace              
    INMUMWANRT01#traceroute 192.168.20.205
    Type escape sequence to abort.
    Tracing the route to 192.168.20.205
    VRF info: (vrf in name/id, vrf out name/id)
      1 192.168.20.226 24 msec 24 msec 24 msec
      2 192.168.20.206 [AS 8035] 232 msec 232 msec 252 msec
      3 192.168.20.205 [AS 8035] 224 msec 224 msec *

  • Please explain me how I can use Form feed(\f) and Carriage return(\r)

    what is Form feed(\f) and Carriage return(\r)?
    Please explain to me.
    Thank you.

    These control characters aren't used much these days except that if you example a Windows or MSDOS text file in a binary editor you'll find each line ends with "\r\n". However when reading or writing text through classes these carriage returns will be added and removed automatically so your program doesn't see them.
    The controlls date back to teletype machines which operated rather like typewriters. Cariage return, as it's name implied, caused the print head to move back to the start of the line, line feed advanced a line (without, necessarilly, returning the carriage) and formfeed skipped to the next page.
    Newline on these machines was always "return, linefeed" because executing the carriage return on these machine could take too long. The early machines had only a single character buffer so that they had to executed the characters as quickly as they arrived. So doing the linefeed after the carriage return gave the carriage more time to return. On some teletypes if you did "linefeed, return" then the first character of the new line would often be printed somewhere in the middle of the line.
    This is the origin of the MSDOS/Windows end of line sequence.
    Many printers will still respect formfeed if printing is direct. Some will take carriage return without linefeed to allow you to start again overprinting the same line.
    However printing, these days, is seldom direct but done in bitmap form.

  • Please explain me, how to remove an usb stick or memory chip? With experiences only in pc:s, I do not find on my first apple e.g. MacBook Air a solution. Until now I have succeeded to destroy one chip full of photos and - there's no life more in the port.

    Please explain me, how to remove an usb stick or memory chip? With experiences only in pc:s, I do not find on my first apple e.g. MacBook Air a solution. Until now I have succeeded to destroy one chip full of photos and - there's no life more in the port...
    Someone told me just to remove the chip in clicking it to the trash can and voilá - it would be done. But as I did so, on the screen appeared a text which let me know, that that way had been the wrong one...
    I should have clicked Finder plus something.... which I do not now remember but which was then not found behind the Finder.
    So please would someone be so kind and tell me, where I can find explanations for the most simple functions. The manual I got does not include a clue.
    Thank you!

    First make sure that no application is using or has open any files on the disk. Then:
    Click and drag the disk icon on the desktop to the trash. Wait for the system to recognize the action, and the icon should disappear from the desktop. It is then safe to remove the device.
    Alternatively, you can secondary click on the disk icon, and then primary click "Eject (name of disk)". Wait for the icon to disappear off the desktop, and then it is safe to remove the drive.
    Here is a detailed help document on the subject.
    http://docs.info.apple.com/article.html?path=Mac/10.7/en/mchlp1056.html

  • Hi any one please explain background job scheduling

    Hi any one please explain background job scheduling . Good answer can be rewarded.
    Thanks

    Background jobs are pgms that are scheduled to be run in the Background without user interaction. So this can be done only for Type 1(executable) Program and not for Module-Pool Programs. Typically, a variant is defined and the pgm is run using the same.
    The transaction code is sm36 -Define Background job. Using the Start Condition tab you can define when you want the job to run (specific time or if it has to follow after a particular job is done etc.,) Using the Step tab you can assign the pgm name and variant.
    After the job is scheduled, you can check the status in sm37, along with the Job log and Spool.
    For more info:
    http://help.sap.com/saphelp_bw30b/helpdata/en/c4/3a7f87505211d189550000e829fbbd/content.htm

  • Can someone please explain how I download all my songs from the cloud without having to tick each cloud individually for each song

    Can someone please explain how to download all my songs from cloud without having to tick each cloud individually

    Music > iTunes Store > Music Quick Links > Purchased > Not in My Library > Download All.
    tt2

  • My macbook air will not connect to the internet due to a self assigned IP address. I have tried trawling the support forums, but either I can't understand the suggestions, or they don't work. Please explain to me in simplest terms how to fix this. Thanks!

    My macbook air will not connect to the internet due to a self assigned IP address. I have tried trawling the support forums for hours, but either I can't understand the suggestions, or they don't work. Please explain to me in simplest terms how I can fix this. Many thanks!

    The warranty entitles you to complimentary phone support for the first 90 days of ownership.
    If you bought the product in the U.S. directly from Apple (not from a reseller), you have 14 days from the date of delivery in which to exchange or return it for a refund. In other countries, the return policy may be different. If you bought from a reseller, its return policy applies.

  • I am having email problems with the new Lion.  stmp, imap, etc. I have looked up google info and It is confusing when it comes to TS, SSL also, please explain how to set it up so my email goes out and comes in securely.  Help

    I am having email problems with the new Mountain Lion.  stmp, imap, etc. I have looked up google info and It is confusing when it comes to TS, SSL also, please explain how to set it up so my email goes out and comes in securely.  Help
    Incoming Mail (IMAP) Server - requires SSL:
    imap.gmail.com
    Use SSL: Yes
    Port: 993
    Outgoing Mail (SMTP) Server - requires TLS:
    smtp.gmail.com (use authentication)
    Use Authentication: Yes
    Use STARTTLS: Yes (some clients call this SSL)
    Port: 465 or 587
    Account Name:
    your full email address (including @gmail.com) Google Apps users, please enter username@your_domain.com
    Email Address:
    your full Gmail email address ([email protected]) Google Apps users, please enter username@your_domain.com
    Password:
    your Gmail password
    The Quick Answer
    Follow the instructions below to set up IMAP1 access in most email clients.
    Google Apps users, please follow the default instructions unless otherwise noted, replacing 'your_domain.com' with your actual domain2 name.
    this is all greek to me. WHAT IS STARTTLS? On the first page of Apple set up there is a TLS certificate and it is marked NONE- should I change it to the long APPLE CERT option?  The next page under ADVANCED: THERE IS A BOX SSL MARKED.  Then IMAP Path Prefix - I put stmp.gmail.com.. is that right?  Port 993 can  use this one? as 456 doesn't work and 587 said it wasn't safe.  Under AUTHENTICATION I used PASSWORD.  Should I have used external client cert TLS?
    Please help me set this up securely. Thanks

    Apple - Support - Mail Setup Assistant

  • I just purchased a new laptop, so consequently had to buy Itunes Match to get all of my music back. Now everything is in the cloud, and I can't play them and cannot make a cd. Please explain how I can get

    I just purchased a new laptop, so consequently had to buy Itunes Match to get all of my music back. Now everything is in the cloud, and I can't play them and cannot make a cd. Please explain how I can get my library out of the cloud and keep them on my computer so they are available when I want them? Wow.......why have you made everything so difficult now?

    SKF5656 wrote:
    I just purchased a new laptop, so consequently had to buy Itunes Match to get all of my music back.
    No you didn't.
    Now everything is in the cloud
    Except for anything you did not purchase in iTunes Store.
    Only you iTunes purchases are in the cloud.
    Reada the article that brenden dv posted to copy your iTunes library to new computer.

  • I would like to know how to extract my old contacts from the iTunes backup? Please explain in basic english i am a beginner

    I have had my old Iphone 5s replaced with a new one but I would like to know how to extract my old contacts from the iTunes backup? Please explain in basic english i am a beginner

    Hey,
    I think you will find that you have to have a debit/credit card stored on yur account regardless of whether your have iTunes Credit or want to purchase a free App. I don't know why, I assume its for ID verification or is part of the terms and conditions. I occasionally have to re-verify my credit card info even when just trying to run Update on one of my Apps or like I said downloading a free App.
    If you need further clarification all you can do is contact iTunes Support:
                   https://expresslane.apple.com/ServiceOptionAction.action
    Hope this helps. Andrew

  • Could you please explain when we connect R/3 system to BW

    Hi,
    could you please explain when we connect R/3 system to BW
    1. Procedure
    2. SAP BW need to do anything
    3. Effort required by  SAP BW
    Regards,
    kranthi

    Hello Kranthi,
    When we need to make a conncetion between R/3 & BW , First logon to R/3 system , Go to T/code - SM59 .
    There u find connections . Select on ABAP and click on New
    Then Provide the description
    Go to technical settings tab :
    Provide load balancing : No
    if you know the server name : give it in the target host name
    or give the IP Address ;
    Then after that go to logon & Security Tab :
    provide the RFC user ID , Client & Password .
    And now check the connection by clicking on the connection test
    If it shows some 2mins ,like that then it is ok ...
    Otherwise then it is a problem ...
    repeat the same thing by giving the target as R/3 here .
    now go the RSA1 , select the source systems , create source systems
    Select BW source systems
    give the target system details , such as system no . System ID ,server name ..
    And also background user id & password for both the target systemm & source system .
    Now Select the created source system , context menu & Check the connection .
    This job is performed with the help of basis people , not only by BW team .
    This is maintaince is done for every system ( Dev , Qaulity & production seperately )
    Thanks
    PT
    Edited by: PT on Dec 9, 2008 11:17 AM

  • In Pages 09 we can do Mail Merge and Import Styles from a document. Can someone please explain how we can do this with the new version of Pages 5.1. Even Apple solutions are only valid for Pages Version 09. What a DOWN GRADE!

    In Pages 09 we can do Mail Merge and Import Styles from a document. Can someone please explain how we can do this with the new version of Pages 5.1. Even Apple solutions are only valid for Pages Version 09. What a DOWN GRADE! Thank god Pages 09 is still there.

    …and the other 98 missing features.
    Just use Pages '09, which should be in your Applications/iWork folder.
    Rate/review Pages 5 in the App Store.
    Peter

  • Please explain XSLT mapping from initial

    Hi Experts,
    I have Altova XMLspy but I dont know how to use it for doing XSLT mapping.
    Can anyone of you please explain a simple XSLT mapping in Altova so that I can try.I have checked many blogs related to XSLT mapping but didnt find my answers.
    If you can guide me with a simple xslt mapping it would be great.
    Thanks,
    Ravi

    Hi Ravi
    Please check the below links.
    XSLT Tutorial
    http://www.altova.com/documents/XMLSpyTutorial.pdf
    http://www.altova.com/documents/2013/xmlspytutorialstd.pdf
    http://xml-xslt-dtd-xsd.wonderhowto.com/how-to/use-xmlspy-for-xml-editing-217876/
    Regards
    Osman

  • (ABAP) Code in Transformation--Please explain

    I am getting a strange issue when used the below code
    Target : Charasteristic,Data Type CHAR 5
    Code:
    DATA: years TYPE tfmatage,
    months TYPE tfmatage.
    *DATA: result TYPE c LENGTH 5.(Showing error if included:Result is already declared)
    DATA: l_res TYPE p DECIMALS 2.
    IF source-field-/bic/zdob IS INITIAL.
    result = ''.
    ELSE.
    CALL FUNCTION 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
    EXPORTING
    i_date_from = source-field-/bic/zdob
    i_date_to = sy-datum
    i_flg_separate = 'X'
    IMPORTING
    e_months = months
    e_years = years.
    if months 0.
    l_res = years + months / 100.
    WRITE l_res TO RESULT.
    else.
    write years to RESULT.
    ENDIF.
    ENDIF.
    WRITE / RESULT.
    I am using the above code (given by Mat in SDN) as a field routine in Transformations...can any one please explain me in detail(step by step) whats it doing.
    My requirment is to cal age of the employee in YY:MM format based on his DOB & SY datum.
    FIMA_DAYS_AND_MONTHS_AND_YEARS give Years & Months between 2 dates
    Please update me where i was doing wrong
    If months = 0 the the result should be only years
    Ex: if Months & Years of FM Output is 40Y,0M the i want only 40 to be updated insted of 40.00 so that the reason why i enhanced your code
    But it is giving me strange output
    For Output which got months it is being update correctly but
    for output for which months are 0 it is being update as
    If FM output is 40Y,0M
    then the output being updated is ' 40' (2 spaces before 40)
    In report i need to enter 2 spaces before 40 to retrive values of 40
    Please correct error
    Please ask if you need any info
    Thanks

    Hi,
    Are you using transformations?
    You should not use Result because Result field is a part of SAP generated code.
    Exclude declaration of result and check the code.

Maybe you are looking for