my dog learned polymorphism*
The moose likes JDBC and the fly likes how i get an empty resultSet when there is a data ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "how i get an empty resultSet when there is a data ?" Watch "how i get an empty resultSet when there is a data ?" New topic
Author

how i get an empty resultSet when there is a data ?

naved momin
Ranch Hand

Joined: Jul 03, 2011
Posts: 682

hi , i m getting an empty resultSet while retrieving the data with this quary
i doing all the iteration and all with the resultSet.next()
and putting stuff in a vector and when i see that vector is turn out to be empty like this
but i have done most of the thing the same way & they are working fine but they don't have , i guess this is the problem of
where i m getting an empty result set i have tried in another application also but that application also gives me empty result set with the
if i dont putthen it works fine
can you explain this behavior or help me to solve this problem this out ?
complete statement will look something like
the same statement works fine outside java jdbc but returns empty string while using it in java dbc


The Only way to learn is ...........do!
Visit my blog http://inaved-momin.blogspot.com/
Hebert Coelho
Ranch Hand

Joined: Jul 14, 2010
Posts: 754

Maybe the database of your connection URL is wrong.


[uaiHebert.com] [Full WebApplication JSF EJB JPA JAAS with source code to download] One Table Per SubClass [Web/JSF]
naved momin
Ranch Hand

Joined: Jul 03, 2011
Posts: 682

Hebert Coelho wrote:Maybe the database of your connection URL is wrong.

that cannot be posible , because its an huge application an rest of the module is working fine , on the same connection
yes you got it right connection is static .
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3438
    
  47

Obviously the like condition is never met.

Like is a text comparison operator. Using it on a column named Date is suspicious. You should probably use equality operator on that column (Date = ?) or other comparisons (>=, <=). Make sure to bind the value in a type corresponding to the database type of the Date column. If you mix textual and binary (native) representations of the date, an implicit conversion will occur, which can lead to unexpected results. This is actually happening in your code when using JDBC, the date is converted into text using different format, and the condition is therefore not met.
naved momin
Ranch Hand

Joined: Jul 03, 2011
Posts: 682

Martin Vajsar wrote:Obviously the like condition is never met.

Like is a text comparison operator. Using it on a column named Date is suspicious. You should probably use equality operator on that column (Date = ?) or other comparisons (>=, <=). Make sure to bind the value in a type corresponding to the database type of the Date column. If you mix textual and binary (native) representations of the date, an implicit conversion will occur, which can lead to unexpected results. This is actually happening in your code when using JDBC, the date is converted into text using different format, and the condition is therefore not met.

no , sorry i didn't mentioned , i m saving date as a varchar , so there is no need for cast , i m just using like on date as the same way we do for finding something on text
suppose i have date as 1-dec-2011 i can find all the name which has dec and 2011 by doing something like %-dec-2011
the same thing i m trying to achieve and outside java it is working fine .
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18140
    
    8

Perhaps there's something wrong with the code which sets the parameters in that SQL.

You could also experiment to see if you can even match things in that "date which is not really a date" column for equality.
naved momin
Ranch Hand

Joined: Jul 03, 2011
Posts: 682

Paul Clapham wrote:Perhaps there's something wrong with the code which sets the parameters in that SQL.

ya i think that too , can you show me a way to check whether preparedstatement sets the proper thing in the place of "?"

You could also experiment to see if you can even match things in that "date which is not really a date" column for equality.

i have experimented for matching in different columns and even in different tables also , but when ever i use like , it return's me the empty resultSet otherwise everything works fine .
can you help me with this ?



Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18140
    
    8

naved momin wrote:
Paul Clapham wrote:Perhaps there's something wrong with the code which sets the parameters in that SQL.

ya i think that too , can you show me a way to check whether preparedstatement sets the proper thing in the place of "?"


Um... that was supposed to be a hint to show us your code. You've asked enough questions here that you ought to know that sort of thing by now.
Harsha Ka
Ranch Hand

Joined: Mar 14, 2010
Posts: 45

You could probably consider using trunc/round function instead of "like" for date.


SCJP 1.6,Preparing (Tryin to prepare) for scwcd
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how i get an empty resultSet when there is a data ?
 
Similar Threads
Database access, potential threading problem?
ResultSet question
problem in accesing a db from a servlet
Combining fields from 2 resultsets in 1 vector
Problem with DSN less Connection with MS Access 2000