GeeCON Prague 2014*
The moose likes JDBC and the fly likes problem with a select query. Help! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "problem with a select query. Help!" Watch "problem with a select query. Help!" New topic
Author

problem with a select query. Help!

Juan Alonso
Greenhorn

Joined: Mar 15, 2006
Posts: 1
Hi,

Imagine a simple database with a 'documentos' table.

I have a main class: EjecutarSQL1.java, which calls to a BD class: BD.java, in order to make a query to the database.

The problem is when I try to make a query like
select count(*) from documentos
or like
select distinct name from documentos

The output (the problem) is shown below. The source code at the end of the post.

There are four querys:
- a simple select (that works right)
- one with 'count(*)' (does not work, I get an Invalid cursor state error)
- and other two with 'distinct' (first does not work and the other it does).

Code:






And why this code works?. In this case it's only a class: EjecutarSQL.java which querys to the database directly.

Code:




Thanks in advance!
Juanjo

[added some line breaks so page doesn't scroll]
[ March 17, 2006: Message edited by: Jeanne Boyarsky ]
Arul Prasad
Ranch Hand

Joined: Jan 20, 2005
Posts: 57
I hope ur using the same connection object for all the queries.It is bad
practise and also for the Prpeared stmt,

Use different connection object and Prepare statement or use the same object and close the object when u executed the each query...

Nice way to close the Conneciton,ResultSet,PreparedStatemnent to close in finally block...

Hope u Got some info related to ur problem ...


With Regards<br />Arul
 
GeeCON Prague 2014
 
subject: problem with a select query. Help!