• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
naved momin
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe the database of your connection URL is wrong.
 
naved momin
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21559
33
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21559
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 45
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could probably consider using trunc/round function instead of "like" for date.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic