Solved

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

Posted on 2007-03-27
12
225 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 500 total points
ID: 18803854
why don't u just select the max directly

select max(count) from ...
0
Technology Partners: 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 Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

691 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