Solved

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

Posted on 2007-03-27
12
206 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
  • 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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
 
LVL 92

Expert Comment

by:objects
ID: 18803904
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupSum6 challenge 6 86
java 8 lambda expresssions exception handling 3 88
Java - Why doesn't this JFrame work 3 58
Oracle SQL syntax check  without executing 6 50
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

785 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