Solved

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

Posted on 2007-03-27
12
188 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
Comment Utility
>                 if (a>i)

shouldn't that be

                 if (a<i)

what is it u want to achieve?
0
 
LVL 30

Expert Comment

by:mayankeagle
Comment Utility
>> 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
Comment Utility
why don't u just select the max directly

select max(count) from ...
0
 
LVL 30

Expert Comment

by:mayankeagle
Comment Utility
>> 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
Comment Utility
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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:deepanp
Comment Utility
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
Comment Utility
0
 

Author Comment

by:deepanp
Comment Utility

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

Thanks to objects mayankeagle for replying.
0
 
LVL 30

Expert Comment

by:mayankeagle
Comment Utility
But somehow you didn't like my reply :)
0
 

Author Comment

by:deepanp
Comment Utility
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:mayankeagle
Comment Utility
I see addBatch () and executeBatch () both inside the while loop
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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…
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…
The viewer will learn how to implement Singleton Design Pattern in Java.

728 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now