• 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 ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

SQL query not giving any result

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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: 2658
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
  • 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...
 
They worship nothing. They say it's because nothing lasts forever. Like this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic