1

In the given below these two queries the first query runs successfully and display the result but while running second query i am getting no output and no error.

So can any please explain why i am not getting output in second query.

String firstdate="2014-11-01";
String lastdate="2014-11-30";

//1 query       
getschedule=con.getreader_schedule("SELECT startTime,endtime,available,comments FROM   
reader_available_time WHERE startTime BETWEEN '2014-11-01' AND '2014-11-30' AND        
reader_id="+Integer.parseInt("136"));  

 //2 query
 getschedule=con.getreader_schedule("SELECT startTime,endtime,available,comments FROM
 reader_available_time WHERE startTime BETWEEN "+firstdate+" AND "+lastdate+" AND 
 reader_id="+Integer.parseInt("136"));
1
  • 1
    for string parameters you need to place in between single quote as done in query1 when passing static values. in query 2 pass as startTime BETWEEN '"+firstdate+"' AND '"+lastdate+"' ... and it should work. Commented Nov 4, 2014 at 6:13

2 Answers 2

1

Well when you doing second query and giving external parameters u need to do something like this.

getschedule=con.getreader_schedule("SELECT startTime,endtime,available,comments FROM
 reader_available_time WHERE startTime BETWEEN '"+firstdate+"' AND '"+lastdate+"' AND 
 reader_id="+Integer.parseInt("136"));

tihs is what i think its should work.

Sign up to request clarification or add additional context in comments.

Comments

1

Ideally, you should be using prepared statements in your queries, to avoid this kind of issues. For a tutorial on prepared statements(using java), check here


To solve your existing query,

You are not getting output in the second query because, on substitution of the variables, your query would be:

WHERE STARTTIME BETWEEN 2014-11-01 AND 2014-11-30

which is wrong and bound to throw exceptions. Correct query should be

WHERE STARTTIME BETWEEN '2014-11-01' AND '2014-11-30'

which implies, you should change your text to

 WHERE STARTTIME BETWEEN '"+firstdate+"' AND '"+lastdate+"'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.