Quantcast
You are not logged in, click here to log in.
1 Replies Last post: Jun 24, 2004 7:36 AM by d00d  
Click to view lrrdouglas's profile New Member 1 posts since
Jun 24, 2004
Reply

Jun 24, 2004 6:22 AM

finding maximum & minimum value

Hi,
I have connected to excel sheet using jdbc and retrieved the results with the below code
ResultSet rs = st.executeQuery("select organization,price,comm,percent from Total$");
while (rs.next())
{
String s1 = rs.getString(1);
int s2 = rs.getInt(2);
int s3 = rs.getInt(3);
int s4 = rs.getInt(4);
System.out.println( s1 +" " + s2 +" " + s3 +" " + s4);
}
now,I want to find the maximum of (percent) and minimum of (price) columns
and display it one by one. Any suggestion or code examples will be appreciated. Thanx in advance.
Reply
Click to view d00d's profile Macworld Editorial 12,136 posts since
Apr 24, 2001
1. Jun 24, 2004 7:37 AM in response to: lrrdouglas
Re: finding maximum & minimum value
I'm assuming this is a java program that's extracting this information. It's easy and is actually something that should have been covered in any java course or book. I'm going to assume for the purposes of the code sample that s2 is percent and s3 is price (as you haven't named your variables descriptively; change that habit if you're going to program, it makes things hard to work with).

<pre>code:<hr>
int maxPercent = Integer.MIN_VALUE;
int minPrice = Integer.MAX_VALUE;

while (rs.next())
{
String s1 = rs.getString(1);
int s2 = rs.getInt(2);
int s3 = rs.getInt(3);
int s4 = rs.getInt(4);
System.out.println( s1 +" " + s2 +" " + s3 +" " + s4);

if(s1 > maxPercent)
maxPercent = s2;

if(s2 < minPrice)
minPrice = s3;
}

System.out.println("Max percent is " + maxPercent);
System.out.println("Min price is " + minPrice);
</pre><hr>

Keep in mind, that will only identify the values and will not identify the records in which they are contained. For something like that, you'll have to make a data structure to hold these records.