wood burning stoves 2.0*
The moose likes JDBC and the fly likes SQL query not giving any result Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "SQL query not giving any result" Watch "SQL query not giving any result" New topic
Author

SQL query not giving any result

Gayan Herath
Greenhorn

Joined: Dec 09, 2009
Posts: 7
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.
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1135

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

Joined: Dec 09, 2009
Posts: 7
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

Joined: Oct 11, 2000
Posts: 1135

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

Joined: Dec 09, 2009
Posts: 7
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.
Mike Zal
Ranch Hand

Joined: May 04, 2011
Posts: 144

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.


OCJP6, OCWCD5
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2510
    
  10

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...


OCUP UML fundamental and ITIL foundation
youtube channel
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: SQL query not giving any result