File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Head First Android this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "connectivity problem" Watch "connectivity problem" New topic
Author

connectivity problem

geetu hindu
Greenhorn

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(1,request.getParameter("a"));
pstmt.setString(2,request.getParameter("b"));
pstmt.setDate(3, request.getParameter("c"));
pstmt.request.getParameter("d"));
ResultSet rset=pstmt.executeQuery();
if(!rset.next())
{
System.out.println("no data found");
}
else
while(rset.next())
{
rset.getString("DAT")
}
}

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

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 rset.next() 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
Marshal

Joined: Jan 10, 2002
Posts: 63053
    
  69

Moved to JDBC.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Paul Clapham
Sheriff

Joined: Oct 14, 2005
Posts: 19693
    
  10

Gives an error? Would you mind running it again, so you can take note of the error and tell us what it is?
 
Don't get me started about those stupid light bulbs.
 
subject: connectivity problem
 
It's not a secret anymore!