Need help with while loop

Hi,
I'm running a while loop to run through some results of a search. Anyway I know how to list the strings but my last item is a JComboBox (drop down box.) How do I go about changing that so its right for a drop down box. Its the one with questions marks in the code below.
        while (srs.next())
        //Get the values for each field in this row
        String projectName = srs.getString("PROJECT_NAME");
        System.out.println("Project Name = " + projectName );
        String projectOfficier = srs.getString("PROJECT_OFFICER");
        System.out.println("Project Officer = " + projectOfficier );
        String projectDescription = srs.getString("PROJECT_OFFICER");
        System.out.println("Project Description = " + projectDescription );
        String paymentSchedule = srs.getString("PAYMENT_SCHEDULE");
        System.out.println("Payment Schedule = " + paymentSchedule );
        String banksInvestment = srs.getString("BANKS_INVESTMENT");
        System.out.println("Banks Investment = " + banksInvestment );
    ?   String paymentsMade = srs.getString("PAYMENTS_MADE");
    ?   System.out.println("Payments Made = " + paymentsMade );Thanks.

Yeah the Payments Made part is a JComboBox with 3 so called strings inside it. I wanna know instead of srs.getString what should I put in to replace String to get the results from a JComboBox?

Similar Messages

  • Need help with while loop and shift registers

    I have a large data set and need to read in the data at maybe 200 samples at a time, process these samples through my VI, and have it append and concatenate a separate lvm file.  The part where I am confused is the shift registers. How do I limit the number of samples read in an iteration? How do I get the while loop to stop when all the data are read in?
    I've attached my diagram, maybe there is something wrong with my technique?
    Solved!
    Go to Solution.
    Attachments:
    shiftreg.JPG ‏56 KB

    This will give you an idea.  There are plenty of other (probably more efficient) methods.  This is a basic, quick and dirty solution to help you grasp the overall concept.
    Using LabVIEW: 7.1.1, 8.5.1 & 2013
    Attachments:
    ShiftRegLoop.JPG ‏54 KB

  • Need help with while loops

    Hello let me first explain what im trying to achive:
    I want a moving square that you control with the arrow keys on the keyboard. It has to be smooth ie able to move fast without looking like its jumping and it has to be able to move diagonaly aswell. Think of that arcade game Raiden ...you know the birds-eye view plane flying game...another thing! I'd prefer if it didnt use timers - i made one already using 4 timers and it works great but 4 timers is a little extreme - SO NO TIMERS !
    I was thinking while loops, but i cant seem to get it working. I dont want to put in all the code so ill just say that I have 4 booleans: up, down, left right and the following code:
    public void keyPressed(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_UP) {
    up = true;
    if (e.getKeyCode() == KeyEvent.VK_DOWN) {
    down = true;
    if (e.getKeyCode() == KeyEvent.VK_LEFT) {
    left = true;
    if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
    right = true;
    repaint();
    For the KeyReleased part i have the same as above exept it sets the booleans to false.
    Soooo in theory if i set up a while loop like this (using the up direction as an example) :
    while (up == true) {
    [move square up]
    So therefore when i press and hold the up arrow the loop will keep going untill i realease it right? WRONG ! it just keeps repeating indefinatly and it doesnt even do the " [move square up] " bit. I put a System.out.print in the loop to test and it kept printing out the message but it still didnt do the actual " [move square up] " bit.
    Im not sure if im putting the while loop in the right place either....If anyone has any idea on how to use while loops in this way please heeeelp ! Its so annoying because it just doesnt work ive tried so many ways...
    any help would be greatly apreciated !!!!

    Maybe you want something like this? You have to pause during the loop to allow for other events to happen, like if y ou release a key or whatever.
    while( true )
       if( up ) moveUp();
       else if( down ) moveDown();
       if( left ) moveLeft();
       else if( right ) moveRight();
       try
          Thread.currentThread().sleep(10);
       catch( InterruptedException e )
          System.out.println( "Thread interrupted!");
    }

  • Need help with while loop format

    I'm building a form - everything works but I would like to change the way the data is output into the table.
    In other scripting languages, like PHP, you had 2 different ways of dealing with a loop:
    <?
    do while xyz
    do something here
    ?>
    - OR -
    <? do while xyz:?>
    do something here
    <?end while ?>
    I would like to do something similar to the 2nd example in .jsp but I'm not sure of the format or how to stop the loop. From the tutorial, I'm using
    <%
    while(SQLResult.next())
    UId = SQLResult.getString("uid");
    FName = SQLResult.getString("fname");
    LName = SQLResult.getString("lname");
    out.println("<tr><td>" + UId + "</td><td>" + FName + "</td><td>" + LName
    + "</td></tr>");
    %>
    Could anyone point me in the right direction? I'd prefer it if I didn't have to build the table like this if I don't have to but haven't found anything anywhere telling me otherwise.
    Thanks so much.
    Bob

    Sorry - the answer was in JSP:Java Server Pages by Barry Burd. I had just gotten the output format wrong.

  • Help with while loops

    Im trying to create a while loop that outputs the revers of a string, eg nice one
    would be "eno ecin" Assuming i already have declared a variable intital string that holds the string, how do i go about this does anyone have any problem solving techniques. The charAt method needs to be used.

    i have a exam on saturday and it was a previous exam question that im trying to get help with i need to understand the course material thanks, i know how to use while loops but have trouble getting my head around this question. ill show you my code however i know its completely wrong.
    now i know i hvae to use the charAt method to return a character located at the integer i
    so i must go down after each case has been tested true therefore i want i=i-1;
    until i=0;
    String initialString="tucan";
    int i=initialString.length();
    while(i>0)
         return charAt();
         i=i-1;
         }

  • Need help with the loop

    I'm a beginner. I'm trying to get this output
    Initial number of stars:
    7
    Here's my program. What's wrong with it? Please help
    import java.io.*;
    class starWedge
    public static void main (String[] args ) throws IOException
    int numStars; // the number of stars
    int row ; // current row number
    int star; // the number of stars in this row so far
    BufferedReader userin = new BufferedReader (new InputStreamReader(System.in));
    String inputData;
    // collect input data from user
    System.out.println( "Initial number of stars:" );
    inputData = userin.readLine();
    numStars = Integer.parseInt( inputData );
    row = 1;
    while ( row <= numStars )
    star = 1;
    star = numStars - star;
    System.out.print("*");
    star = star + 1;
    System.out.println(); // end each line
    row = row + 1;

    Okay the one thing that I see immediately is that your while loop never actully exits. Not once. Why? Well simple your exit condition is the row <= numStars, yet nither numStars nor row actually change their values within the loop. In short row always equals 1 and thus never is equal to greater than numStars and the while loop does not terminate.
    Second thing is that your star drawing logic is not correct. Meaning you have not told to draw the specific number of stars in one given line. For starters the System.out.println() command should be in the loop not outside it. For your purposes a for-loop nested within a while-loop is much better.
    If you think you know what's wrong your program than read no further and go try it on your own. But if you still have no clue below is my modification of your code that actually produces the pattern you want, it might provide you with more hints.
    import java.io.*;
    class starWedge{
    public static void main (String[] args ) throws IOException{
         int numStars; // the number of stars
         int row ; // current row number
         int star; // the number of stars in this row so far
         BufferedReader userin = new BufferedReader (new InputStreamReader(System.in));
         String inputData;
         // collect input data from user
         System.out.println( "Initial number of stars:" );
         inputData = userin.readLine();
         numStars = Integer.parseInt( inputData );
         row = 1;
         while (numStars > 0){
         for(star = 1; star<=numStars; star++){
              System.out.print("*");
         numStars = numStars - 1;
         System.out.println(); // end each line
    }

  • I need help with a loop within an hour

    I need to make a loop that gives 100, 10, 1000, 100, 10000, 1000...
    I can use a for loop, if loop, while loop, and do while loop.
    Thanks

    warnerja wrote:
    sharkura wrote:
    warnerja wrote:
    sharkura wrote:
    Sorry warnerja. I know I should have done the same. I just couldn't help myself. I need to keep telling rubbish.
    :D
    ¦ {ÞIt's not too late to edit your spoon-fed solution, though the OP may have seen and copied it by now.And you know this isn't going to make the OP a programmer, unless he/she/it changes his/her/its stripes.
    ¦ {ÞYes, but its laziness will continue to be encouraged more than it should.Nah. It'll crash and burn on the next assignment.
    ¦ {Þ                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Noob Help with While Loop

    Sorry for the "Noob"-ness on this one. I am working on a program for class and I am having a problem with a while loop. So I opened a new document and began to code a while loop that is basic to test my while looping skill. Apparrently, I have none. Can anyone tell me why this While Loop will not work:
    public class test
         public static void main(String[] args)
         int LoanTerm = 0;
              while (LoanTerm < 3);
                   System.out.println (LoanTerm);
                   LoanTerm++;
    Thanks.
    FatherVic

    to explain, the ; means that the while loop body is empty, and you will just spin forever testing whether LoanTerm < 3, without doing anything else.

  • Help with while loop program

    I am working on this program that when inputing two integers: firstNum and secondNum, the program will output all odd numbers between firstNum and secondNum.
    This program will be using a while loop and I can't find any similar examples in my book on how to write the code.
    any help would be greatly appreciated

    you asked for it...
    //This program will prompt the user to input two integers.
    //Output all odd numbers between firstnum and secondnum.
    //Output the sum of all even numbers between firstnum and secondnum.
    //Ouput the numbers and their square between 1 and 10.
    //Output the sum of the square of odd numbers between firstnum and secondnum.
    //Output all uppercase letters.
    import java.io.*;
    public class Program8
              static BufferedReader keyboard = new
                        BufferedReader(new InputStreamReader(System.in));
              public static void main(String[] args) throws IOException
              //Declare all variables
              int firstNum;
              int secondNum;
              System.out.print("Input first Integer: ");
              firstNum = Integer.parseInt(keyboard.readLine());
              System.out.println();
              System.out.print("Input second Integer: ");
              secondNum = Integer.parseInt(keyboard.readLine());
              System.out.println();
    As you can see, I don't have a clue where to begin after this...

  • Need help with infinite loop in recovery mode in Creative Zen 20

    hi,
    I'm having this problem with my Creative Zen 20 GB:
    When I turned it on, it goes immediately to the rescue/recovery mode. Not sure why. Will do that even when I reset the device.
    So, I selected cleanup. After cleanup, it remained showing the menu of the recovery mode. I selected reboot. After reboot, it went back to the rescue/recovery mode. And it goes on and on like an infinite loop.
    Finally, I decided to do a formatAll. Again, it remained in the recovery mode menu after the formatAll action. After reboot, it again went back to the rescue/recovery mode.
    I have never updated the firmware. So, I thought maybe that will help. However, when I connected the device to my PC, the device went to rescue/recovery mode and the PC could not detect the device connected via USB. In short, I am currently not able to do anything at all with the device except charging it.
    Would appreciate help/advise.
    Tks in advance.

    huggiebear wrote:
    I connected the device to the PC and after the PC tried to load the library, it said "Player is not connected".
    What library are you loading? After you have run that reload os option, you need to connect the player to the computer and run the firmware update software. If you haven't download that, you can go to the download section and download it. If all else fail, the player is probably faulty and you would need to get in contact with Customer Support then.
    Jason

  • Help with while loop

    Im trying to finish this loop for a guessing game, does anyone have any suggestions, thanks.
    class guess
    {public static void main ( String[] args )
    int secretNumber = 4;
    InputStreamReader inStream =
    new InputStreamReader( System.in ) ;
    BufferedReader stdin =
    new BufferedReader( inStream );
    String userGuess;
    int guess;
    System.out.println("Enter your guess:");
    userGuess = stdin.readLine();
    guess      = Integer.parseInt( userGuess );
    System.out.println("You entered:" + guess );
    if ( guess = secretNumber )
    System.out.println ("Guess is correct!")
    else
    System.out.println ("Guess is incorrect")
    while ( (guess == secretNumber) = false ) //evaluates true or false
    }

    Hie.
    Your logic is not good here.
    You should do this :
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.util.Random;
    public class Guess {
         public static void main(String[] args) {
              BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
              int secret = new Random().nextInt(10);
              boolean guessed = false;
              System.out.println("Guess the number (0 to 9, inclusive) :");
              while (!guessed) {
                   System.out.print("Your guess : ");
                   System.out.flush();
                   int guess = -1;
                   while (-1 == guess) {
                        try {
                             guess = Integer.parseInt(in.readLine().trim());
                             if (0 > guess || guess > 9) {
                                  System.out.println("You should type an integer between 0 and 9 inclusive.");
                                  guess = -1;
                        } catch (NumberFormatException nfe) {
                             System.out.println("Type an INTEGER !");
                             guess = -1;
                        } catch (Throwable t) {
                             t.printStackTrace();
                             guess = -1;
                        guessed = guess == secret;
                        if (!guessed && -1 != guess) {
                             System.out.println("Wrong ! Try again.");
              System.out.println("Right ! bye.");
    }Tell me if you need explanations.

  • Need help with nested loop (c:forEach) tags. Can I break from inner loop?

    Hi all, I have this annoying problem and I am looking for any suggestions.
    I have 2 select boxes. One is for all available users, and second - for selected users (designated as admins). The list of all users is available in a collection (2 properties userId and userName displayed in the code below). The list of admins contains only userId (as strings).
    I have no problem with populating selected users (admins) list, reusing pretty much the same logic below, but I cannot find a way to break out from the nested loop once the match is found, to avoid repetitions leading to incorrect display of results.
    <select name=available>
    <c:forEach items="${users}" var="user" varStatus="outer">
        <c:forEach items="${adminIds}" var="adminId" varStatus="inner">
            <c:if test="${user.userId!=adminId">
                 <option value="<c:out value="${user.userId}" />"><c:out value="${user.userFullName}"/></option>
            </c:if>
        </c:forEach>
    </c:forEach>
    </select>
    <select name=selected>
    <c:forEach items="${users}" var="user" varStatus="outer">
        <c:forEach items="${adminIds}" var="adminId" varStatus="inner">
            <c:if test="${user.userId==adminId">
                 <option value="<c:out value="${user.userId}" />"><c:out value="${user.userFullName}"/></option>
            </c:if>
        </c:forEach>
    </c:forEach>
    </select>Can anyone help, please? I am also restricted to JSP 1.2

    Double post: http://forum.java.sun.com/thread.jspa?threadID=707950&tstart=0

  • Need help with simple loops

    Hi I am having a very very difficult time. for thos that have it I'm using the Intro to Java Programming 6th Edition by Y.Daniel Liang Book. I am on page 124 Ch 4 Problem 4.18
    what it wants you to do is make and use nested loops that print
    Pattern 1
    1
    12
    123
    1234
    12345
    123456
    Pattern 2
    123456
    12345
    1234
    123
    12
    1
    Patern 3
    1
    21
    321
    4321
    54321
    654321 ( I know this is crooked but you get the idea )
    Pattern 4
    123456
    12345
    1234
    123
    12
    1 (once again crooked but you get the idea )
    Ok so here is my code thus for and it includes pattern 1 and pattern 2...Keep in mind I'm just simply printing them out one right after the other..it doesnt have to look all pretty or nothing like that ok...thanks
    public class Patterns
    // Print Pattern I */
    public static void main(String[] args)
    for (int i = 1; i <= 6; i++)
    for (int j = 1; j <= i; j++) ( NESTED FOR STATMENT)
              System.out.print(j + " ");
         System.out.println();
    // Print Patter II
         for ( int i = 6 ; i >=1; i--)
              for ( int j = 1; j <= i; j++) (NESTED FOR STATMENT )
                   System.out.print ( j + " ") ;
              System.out.println();
    If yall could somehow give me hints as to how to get number 3 and number 4 thanks
    -tim-

    package src;
    public class Escada {
        public Escada(){
            System.out.println("Pattern1");
            for (Integer i = 1; i <= 6; i++){
                for (Integer j = 1; j <= i; j++){
                    System.out.print(j);
                System.out.println("");
            System.out.println("--------\nPattern2");
            for (Integer i = 6; i >= 1; i--){
                for (Integer j = 1; j <= i; j++){
                    System.out.print(j);
                System.out.println("");
            System.out.println("--------\nPattern3");
            for (Integer i = 1; i <= 6; i++){
                for (Integer j = i; j >=1; j--){
                    System.out.print(j);
                System.out.println("");
            System.out.println("--------\nPattern4");
            for (Integer i = 6; i >= 1; i--){
                for(Integer j = 1; j <= i; j++){
                    System.out.print(j);
                System.out.println("");
        public static void main(String[] args) {
            new Escada();

  • Help with do loop

    do{     
    if((orderType != 'g') || (orderType != 'w')){     
    System.out.println("Please enter g or w only.");
    }while((orderType == 'g') || (orderType == 'w'));
    I need help with this loop... I have to make sure it will be able to pop the input back after the invalid input... i tried to fix it...wont stop and stay in same loop till it gets the valid before go to other loop... how? am i missing something?

    I know you've already been answered, but just a bit more...
    if((orderType != 'g') || (orderType != 'w'))That would always be true. All characters are either not equal to 'g' or not equal to 'w'.
    'x' : neither 'g' nor 'w'. Evaluates to true.
    'g' : not 'w', still evaluates to true.
    'w': not 'g', still evaluates to true.

  • I need Help with loop

    Hello everyone this is my first time posting here, i have always find java easy(up to this point), this is my first class in programming java i am just needing help with the "for loops" i cant seem to get the program generate 10 random math questions. if you guys can please help i will appreciate it, i have been working on it for a couple of hours. I am not finished with it yet but thats the only thing i need help with.
    import javax.swing.JOptionPane;
    public class Lab5
    public static void main(String[] args)
    int num1 = (int) (Math.random() * 100 + 1);
    int num2 = (int) (Math.random() * 100 + 1);
    int sum = num1 + num2;
    int product = num1 * num2;
    int quotient = num1 / num2;
    int difference = num1 - num2;
    for (int i = 0; i > 11; i++);
    int number = (int)(Math.random()*4);
    if (number == 0 )
    String s1 = JOptionPane.showInputDialog(null, num1 + " + " + num2 + "=" );
    if(number == 1)
    String s3 = JOptionPane.showInputDialog(null, num1 + " - " + num2 + "=" );
    if(number == 2)
    String s3 = JOptionPane.showInputDialog(null, num1 + " x " + num2 + "=" );
    if(number == 3)
    String s4 = JOptionPane.showInputDialog(null, num1 + " &divide; " + num2 + "=" );

    for (int i = 0; i > 11; i++);Two problems with this line:
    1) The second part of a For loop is the constraint. You have said that for the loop to be entered, i must be greater than 11. Well since you've also told i to begin at 0, this will never happen. Thus, the loop will never enter. You may have meant less than?
    2) You put a semicolon in the line. Semicolons are used to end statements. The For loop, when used as a block with curly braces, is not a single statement and does not require a semicolon. Here's the two structures of a basic For loop:
    for(int i = 0; i <= 100; i++) {
        //this is a block. you can put multiple statements in here and they are all part of the loop
        int a = 1;
        int b = i;
    //if your loop only needs to use a single statement, no braces are required
    for(int i = 0; i <= 100; i++)
        int a = i;

Maybe you are looking for