max(columnname) problem

hi,

i'm using oracle 8i and jdk 6

protectedint getItem()

{

int queue=0;

str="select nvl(max(queueno),0) as queue from jobprocess";

DBConnector dbcon=new DBConnector();

try

{

ResultSet rs=dbcon.getStatement().executeQuery(str);

if (rs.next())

queue=Integer.parseInt(rs.getObject(1).toString());

rs.close();

}

catch(SQLException sqlE)

{

sqlE.printStackTrace();

}

finally

{

dbcon.close();

return queue;

}

}

there are 164 rows in that jobprocess table.

As expected it should return 164, but returns 0. what is the wrong in above code

how to use sql aggregate functions using resultset.

please help me

thanks & regards,

s.mohamed asif

[1349 byte] By [Mohamed_Asifa] at [2007-11-27 4:38:22]
# 1
Sounds like you intended to use count() instead of max(). Max returns the highest value contained in the column, whereas Count returns the number of rows.
dcmintera at 2007-7-12 9:48:48 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

hi,

thanks for your immediate response.

the requirement is correct.

queueno is just like serial number, you can either use max() or count() both functions will satisfy my need.

but the problem is i'm unable to use these functions in executeQuery.

result set is empty set return 0.

thanks & regards,

s.mohamed asif

Mohamed_Asifa at 2007-7-12 9:48:48 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
If you use getInt (I can't see a reason why you're not)rs.getInt(1)do you get the same problem?
ChristopherAngela at 2007-7-12 9:48:48 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4
hi,still i get the same probleminstead of rs.getInt() you can use rs.getObject().if sql uses aggregate functions and use rs.getInt() will result in compile time error.regards,s.mohamed asif
Mohamed_Asifa at 2007-7-12 9:48:48 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5
What does the SQL return when you run it in an SQL interpreter?Does the Java code enter the "if (rs.next())"?Print out rs.getObject(1).toString() to see what it is.
sjasjaa at 2007-7-12 9:48:48 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 6
> if sql uses aggregate functions and use rs.getInt()> will result in compile time error.No it won't. What are you talking about?
dcmintera at 2007-7-12 9:48:48 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 7
As a side note while we wait for you to answer sjasja .The nvl in your select will not work as I suspect you might think. nvl is called when a value is null. If no rows exists in jobprocess there will be no results ergo no null ergo nvl will not be called.
ChristopherAngela at 2007-7-12 9:48:48 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...