Home » Developer & Programmer » JDeveloper, Java & XML » Query output
Query output [message #91131] Tue, 23 April 2002 05:28 Go to next message
Jules
Messages: 4
Registered: February 2002
Junior Member
Im trying to retrieve one value from my database, and
print it to screen, but the value is always
incorrect: here is the code snipit:

rs = stmt.executeQuery("SELECT COUNT (*) FROM rooms" ;

while ( rs.next() ) // move to first row
{
j = rs.getInt(1);
System.out.println("rooms currently in hotel: " + j);
}

-----

now i know the query is correct cos when i'm in
oracle and use that query it returns the correct
value. j shouuld be the number of rooms, yet it
always outputs it as 0. Does any1 know where this
error is coming from? I think its the j =
rs.getInt(1) line but i don't know how to fix it.

cheers

J
Re: Query output [message #91132 is a reply to message #91131] Tue, 23 April 2002 06:39 Go to previous message
Torsten
Messages: 4
Registered: April 2002
Junior Member
Hi J,

are you sure you are in the same schema when using the Java class and when using Oracle interactively (i.e. are you connected as the same user)? Sometimes the same table name exists in two schemes with different content. Happened to me sometime ago. Otherwise the code looks like some working code I use (see below).

Regards,

Torsten
------------------------

String countQuery = "select count (ID) from MASTER";

try {Statement cs = conn.createStatement ();
ResultSet crs = cs.executeQuery (countQuery);

crs.next ();

if (crs.getInt (1) < 1)
{Tools.showMessage ("No data available");
cs.close ();
return;
}
else {bulkCount = crs.getInt (1);
cs.close ();
}
}
catch (SQLException e)
{Tools.errorMessage (e);
return;
}
Previous Topic: Re: Casting ResultSet to OracleResultSet
Next Topic: Exception in thread "main" java.lang.NoClassDefFoundError: mystery/class
Goto Forum:
  


Current Time: Fri Mar 29 09:03:38 CDT 2024