Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

problem with a select query. Help!

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Imagine a simple database with a 'documentos' table.

I have a main class:, which calls to a BD class:, 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).


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


Thanks in advance!

[added some line breaks so page doesn't scroll]
[ March 17, 2006: Message edited by: Jeanne Boyarsky ]
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ...
when your children are suffering from your punishment, tell your them it will help them write good poetry when they are older. Like this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic