Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting date from oracle table

 
Aravind Prasad
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ranchers..
I'm using JSP and Oracle for doing a project
the table details for the particular table is like this

sailing_date date nulls

so in the resultset when i try to get the values in dd/mmm/yyyy format it is showing no values..

the code i've done like this
-------------------------------------------------------------------------

Calendar timeNow = Calendar.getInstance();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MMM/yyyy");
Resultset rs = stmt.executeQuery(query);
String sail_date="";
while(rs.next())
{ if(rs.getDate(1)==null)
sail_date="";
else
dateFormat.format(rs.getDate(1));
}
out.println(sail_date);

--------------------------------------------------------------------------
if there is no date value in the table then it is displaying fine..
if there is date values .. it is showing error..
the error is

java.sql.SQLException: No data found

But there is a date value in the table..
if i remove all the formating and put just
while(rs.next())
{ sail_date = rs.getDate(1);
}
out.println(sail_date);
it is showing the date from the table..

What may be the problem.. ranchers
Please help me..

Thanks in advance..
regards
Aravind
 
stu derby
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you read the JavaDocs for ResultSet, here:
http://java.sun.com/j2se/1.5.0/docs/api/java/sql/ResultSet.html
you will see that they say:
For maximum portability, result set columns within each row should be read in left-to-right order, and each column should be read only once.

I don't know that that's your problem, but try this:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic