0

How to get the date datattype from sql database to java??? so far I have use this code but failed to fetch the date.

import java.sql.*;//this is my import file
     String search="select * from tblflight";//select all data from my table
     ResultSet rs=stmt.executeQuery(search);//puting result in temporary var
     while(rs.next())
{
   Date d_time=rs.getDate("date_time");//getting result
   combo_box.addItem(d_time);//n showing error here while putting the date var here
}
1
  • "showing error here" doesn't tell us anything about the error. Please provide more details. Commented Apr 1, 2014 at 11:34

2 Answers 2

1

You have two options.
1 - Take sql date object and construct utils date using the getTime method of sql date
or
2 - call getTimeStamp instead of getDate , It will return object of sql timeStamp class that is actually child class of java.util.Date

1 -  Date d1 = new Date(rs.getDate("date_time").getTime());
2 -  Date d2 = rs.getTimestamp("date_time");
Sign up to request clarification or add additional context in comments.

1 Comment

Actually it's diplaying Item1,item2,item3 and item4 but not datetime.. but when I Click any of the list then it show my datetime list How to show my datetime column instead of showing item1,item2,item3 and item4. Your help would be more appreciated. thanx
0

If combo box is not allowing object to inserted, while adding it to the combo_box use d_time.toString() method.

1 Comment

Actually it's diplaying Item1,item2,item3 and item4 but not datetime.. but when I Click any of the list then it show my datetime list How to show my datetime column instead of showing item1,item2,item3 and item4. Your help would be more appreciated. thanx

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.