permaculture playing cards*
The moose likes JDBC and the fly likes connectivity problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
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: 60782
    
  65

Moved to JDBC.


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

Joined: Oct 14, 2005
Posts: 18541
    
    8

Gives an error? Would you mind running it again, so you can take note of the error and tell us what it is?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: connectivity problem
 
Similar Threads
How do I change the content of the combo box based selction on other combo box.
Invalid argument: parameter index 1 is out of range
Between Syntax
parser integer to string
how do i get todays dat without the time