?
Solved

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

Posted on 2007-03-27
12
Medium Priority
?
229 Views
Last Modified: 2010-07-27
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;
}
}
0
Comment
Question by:deepanp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
12 Comments
 
LVL 92

Expert Comment

by:objects
ID: 18803841
>                 if (a>i)

shouldn't that be

                 if (a<i)

what is it u want to achieve?
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 18803848
>> 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
 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 18803854
why don't u just select the max directly

select max(count) from ...
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 30

Expert Comment

by:Mayank S
ID: 18803858
>> 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
 

Author Comment

by:deepanp
ID: 18803864
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
 

Author Comment

by:deepanp
ID: 18803882
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
 

Author Comment

by:deepanp
ID: 18803893
if you could give a link for the maxcount. i cannot seem to fine any links atm..

Cheers!
0
 

Author Comment

by:deepanp
ID: 18804002

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

Thanks to objects mayankeagle for replying.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 18804588
But somehow you didn't like my reply :)
0
 

Author Comment

by:deepanp
ID: 18804595
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
 
LVL 30

Expert Comment

by:Mayank S
ID: 18804792
I see addBatch () and executeBatch () both inside the while loop
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month15 days, 6 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question