1
Date dateformat=null;
Date i5Date=null;

SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
String date = i5t1.getText();

i5Date=(Date) formatter.parse(date);



while(rs.next())
{
rs.moveToInsertRow();
rs.updateDate("Date",i5Date);
rs.insertRow();
}

This doesnt update the resultset in date format. May i know what changes i have to make to update the resultset in date format. (Note : - I dont want to update in string format.) Note: - i have made the connections and the resultset is opened.

Toms
  • 239
  • 1
  • 5
  • 15
  • Noting will change the format of a Date value stored in the database, that's kind of the point, the format is irrelevant only the value of the date is important, that way, when you want to, you can format how ever you want. Try this, use System.out.println(i5Date); I bet it's not in the format of "dd/MM/yyyy" – MadProgrammer Mar 02 '14 at 07:00
  • So, do you mean that if i make the updation in string format, it doesnt matter it all? My requirement is that in another frame when i enter the start date and End date, i should be able to retrieve all the reports between them. Can i achieve it using date as String.? – Toms Mar 02 '14 at 07:13
  • You can convert the Strings to Dates and use between SQL function – MadProgrammer Mar 02 '14 at 07:16
  • can you help me with an example.. – Toms Mar 02 '14 at 07:19
  • I updated my answer to show how to retrieve between dates. If you google the topic, you will find tons of resources that will help. – Emmanuel John Mar 02 '14 at 07:27

1 Answers1

2

The date in result set is a java.sql.Date type. You are trying to format java.util.Date.

You need to convert between them to get this to work assuming you are just rendering the date. If not you need to make the change directly to your schema. See these SO posts:

ResultSet.getTimestamp("date") vs ResultSet.getTimestamp("date", Calendar.getInstance(tz))

java.util.Date vs java.sql.Date

Update To retrieve between dates like you are trying to do, you need to do:

Connection conn = null;
PreparedStatement pstmt = null;

conn = getConnection();
String query = "select * from table_name between ? and ?";
pstmt = conn.prepareStatement(query);
pstmt.setDate(1, new java.sql.Date(startDate.getTime()));
pstmt.setDate(2, new java.sql.Date(endDate.getTime()));

ResultSet resultSet = pstmt.executeQuery();
Community
  • 1
  • 1
Emmanuel John
  • 2,296
  • 1
  • 23
  • 30
  • Thanks for the help. I got these are two different things. But, can the resultset be updated using the style of code i am using? – Toms Mar 02 '14 at 07:40
  • i meant like opening the result set and update the value of column – Toms Mar 02 '14 at 08:07