PLEASE HELP. 500 EASY POINTS FOR URGENT HELP!! SIMPLE PROBLEM, DOESN'T SEEM TO WORK!!

Hey Experts, I'm really fustrated, for some reason this loop doesn't seem to work when going through..

I'm using postgres which gets a sequence count from a table in a col.. the rs.next scans through the rows, i.e. 1,2,3,4,5,6,7,8.... 8 being the highest say for example, i want the if condition to be true. However, this does not seem to work.

Please reply if you hace any questions.

Thanks Experts.


int a = 0;
while (rs.next())
{
                 String temp2 = rs.getString ("count");
                 System.out.println("temp2="+ temp2);
                 int i = Integer.parseInt(temp2);
                 
                 if (a>i)
{
                          a++;
                          String astring = Integer.toString (a);
                    Statement temp3 = temp.createStatement();
                    System.out.println("Whats Up-"+astring);
                  temp3.addBatch("INSERT INTO count_table (name) VALUES ('User generate value = " + astring + "');");
                  temp3.executeBatch();
                  collem = "al" + astring;
                  break;
}
}
deepanpAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

objectsCommented:
>                 if (a>i)

shouldn't that be

                 if (a<i)

what is it u want to achieve?
0
Mayank SAssociate Director - Product EngineeringCommented:
>> temp3.executeBatch();

Should be done outside the while () I guess.

>> break;

Not required perhaps otherwise you will end up looping out when you shouldn't.

>> "');");

Do you need to end the query with a semi colon?

"') " ) ;
0
objectsCommented:
why don't u just select the max directly

select max(count) from ...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

Mayank SAssociate Director - Product EngineeringCommented:
>> temp3.executeBatch();
>> Should be done outside the while () I guess.

Perhaps the create statement too.... what's the use of executing batch if you want to execute only one?
0
deepanpAuthor Commented:
say the col sequence number was 30 right...

the while (rs.next()) will obv go through the rows.. i.e lookin at the count col.. i.e. 1,2,3,4,5,6,.. when it goes through the if loop should check and basically go through the if loop when it reaches the highest value in the col..i.e. if it were 6.. den da next iteration would be 7.. 7 being higher than that of 6.. therefore inserting into table... therefore the next table sequence is then 8.. u get wt i mean?
0
deepanpAuthor Commented:
Hey Objects


I'm going to check out the Maxcount table out right now.. n see if i can try this way... Thanks..


-->>i will post shortly.. so please monitor email... Thanks guys..
0
deepanpAuthor Commented:
if you could give a link for the maxcount. i cannot seem to fine any links atm..

Cheers!
0
deepanpAuthor Commented:

Good technique, and it seems to work fine..!

Thanks to objects mayankeagle for replying.
0
Mayank SAssociate Director - Product EngineeringCommented:
But somehow you didn't like my reply :)
0
deepanpAuthor Commented:
lol... i did...and i understood what you said.. but i had two statements.. one was outside... inside that while loop... was another statement.. thats why i avoided that comment.... :-)
0
Mayank SAssociate Director - Product EngineeringCommented:
I see addBatch () and executeBatch () both inside the while loop
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.