• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SQL query not giving any result

 
Gayan Herath
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.
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • 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: 1141
1
Java Oracle
  • 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.
 
Mike Zal
Ranch Hand
Posts: 144
Fedora Java Oracle
  • 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.
 
Jan Cumps
Bartender
Posts: 2586
11
C++ Linux Netbeans IDE
  • 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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic