• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

SQL query not giving any result

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm trying to get some records by using this query in Java.

;

but this doesn't give any result. but when I executer the query in mysql, It gives some records. Waht could be the reason.

This the table sreucture for myDB




Please give any solution.

Thanks.
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gayan,
Please post your java code for performing the query.
Do you use java.sql.Statement or java.sql.PreparedStatement ?

Good Luck,
Avi.
 
Gayan Herath
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Avi Abrami wrote:Gayan,
Please post your java code for performing the query.
Do you use java.sql.Statement or java.sql.PreparedStatement ?

Good Luck,
Avi.




Hi Avi,

I'm using java.sql.Statement.
Here is my code for the query.



And This my DBConnector class


Thanks for any solution.
 
Avi Abrami
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gayan,
JDBC drivers map database data types to java classes.
Hence from your code, the variables time1 and time2 must be instances of the java class that maps to the BIGINT database data type.
It is not clear to me from the code you posted whether this is the case.
I have no experience with mySQL and therefore do not know what java class maps to BIGINT.
I suggest trying the documentation for the JDBC driver you are using.

Good Luck,
Avi.
 
Gayan Herath
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Avi Abrami wrote:Gayan,
JDBC drivers map database data types to java classes.
Hence from your code, the variables time1 and time2 must be instances of the java class that maps to the BIGINT database data type.
It is not clear to me from the code you posted whether this is the case.
I have no experience with mySQL and therefore do not know what java class maps to BIGINT.
I suggest trying the documentation for the JDBC driver you are using.

Good Luck,
Avi.




Hi Avi,

But this works for this

If this is a problem with type, This wouldn't work no?


Gayan.
 
Ranch Hand
Posts: 144
Oracle Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Gayan Herath wrote:
"SELECT * FROM NetNanny WHERE (status='ACTIVE' AND "+time1+" < nextBilling < "+time2+")";



Your SQL looks messed up. Try the following


With that aside, you should be using a PreparedStatement instead of a regular Statement.
 
Bartender
Posts: 2662
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mike Zal wrote:...

With that aside, you should be using a PreparedStatement instead of a regular Statement.


Yes, and I would use ... nextbilling BETWEEN x and y...
 
I RELEASE YOU! (for now .... ) Feel free to peruse this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic