This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes connectivity problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "connectivity problem" Watch "connectivity problem" New topic

connectivity problem

geetu hindu

Joined: Apr 12, 2006
Posts: 9
my code works if i simple use(select * from MYTABLE) with create statement but gives error if i write the following:

String sql= "Select * from FLIGHT_SCHEDULE where DAT=? and DEPARTURE=? and RETURN_DAT=? and ARRIVAL=?";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setDate(3, request.getParameter("c"));
ResultSet rset=pstmt.executeQuery();
System.out.println("no data found");

can't make out where the problem lies.PLEASE HELP
Carl Trusiak

Joined: Jun 13, 2000
Posts: 3340
There could be two causes first, if there are no rows that meet the Where condition, you won't get any results. Try printing out the parameters you are passing and run the final resultant SQL to check that.

Second and an application bug :

Do you notice what happened when I formatted this, the while statement is inside the else so, it never gets called if you have results. Also every call to will advance the ResultSet to the next record, you will never get the First Record!

Change this to:

I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63548

Moved to JDBC.

[Asking smart questions] [About Bear] [Books by Bear]
Paul Clapham

Joined: Oct 14, 2005
Posts: 19869

Gives an error? Would you mind running it again, so you can take note of the error and tell us what it is?
I agree. Here's the link:
subject: connectivity problem
It's not a secret anymore!