4 messages in com.mysql.lists.javaRE: PreparedStatement.setDate problem| From | Sent On | Attachments |
|---|---|---|
| David Barron | 20 Aug 2004 10:40 | |
| Kevin Dougan | 20 Aug 2004 10:48 | |
| Kevin Dougan | 20 Aug 2004 11:27 | |
| David Barron | 20 Aug 2004 12:20 |
| Subject: | RE: PreparedStatement.setDate problem![]() |
|---|---|
| From: | David Barron (Davi...@sas.com) |
| Date: | 08/20/2004 12:20:04 PM |
| List: | com.mysql.lists.java |
I don't think the control has anything to do with it, frankly.
I checked the value of the Date object I'm getting from the Jspinner and it is a
Date object with the correct value. But when I update the date field its value
doesn't change. Very strange.
-----Original Message----- From: Kevin Dougan [mailto:kev...@stepup.com] Sent: Friday, August 20, 2004 2:28 PM To: David Barron Cc: ja...@lists.mysql.com Subject: RE: PreparedStatement.setDate problem
I haven't used this date control before.
I would suggest you dumps out the values of the "d" and "date" variables throughout your code and see if anything doesn't look right.
Another thing to try is to use a Format against the date variable just as you go to insert it. Here's some more code:
GregorianCalendar cal = new GregorianCalendar(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String timestamp = format.format(cal.getTime());
If even that doesn't work, try using a timestamp column instead of a Date column. It's tried and true, it allows you to get more accuracy (down to milliseconds) and you can also reformat the value anytime you want to extract the date portion.
HTH! Kevin
-----Original Message----- From: David Barron [mailto:Davi...@sas.com] Sent: Friday, August 20, 2004 2:05 PM To: Kevin Dougan Subject: RE: PreparedStatement.setDate problem
Oops Date d = (Date) dateSpinner.getValue(); java.sql.Date date = new java.sql.Date(d.getTime()); dateSpinner is a Swing JSpinner object using a SpinnerDateModel. This is the same code I use to insert the data in the first place so I assumed it would work in an update.
-----Original Message----- From: Kevin Dougan [mailto:kev...@stepup.com] Sent: Friday, August 20, 2004 2:00 PM To: David Barron Subject: RE: PreparedStatement.setDate problem
What about the lines where you create and initialize the "date" variable?
Thanks! Kevin
-----Original Message----- From: David Barron [mailto:Davi...@sas.com] Sent: Friday, August 20, 2004 1:56 PM To: Kevin Dougan Subject: RE: PreparedStatement.setDate problem
PreparedStatement pst = conn.prepareStatement("UPDATE timetrack set area=?,activity=?,tracknum=?,date_entered=?,description=? where number="+number); pst.setString(1,area); pst.setString(2,activity); pst.setString(3,tracknum); pst.setDate(4,date); pst.setCharacterStream(5,new StringReader(dsc),dsc.length()); pst.executeUpdate(); pst.close();
As a test I had System.out.println(pst.executeUpdate()); and got a return value of 1. But the date field wasn't updated.
-----Original Message----- From: Kevin Dougan [mailto:kev...@stepup.com] Sent: Friday, August 20, 2004 1:48 PM To: David Barron; ja...@lists.mysql.com Subject: RE: PreparedStatement.setDate problem
Hi David!
What does your source code look like?
Here's a Timestamp example that I've been using and it works fine for me:
myobject.setLastUpdate(new Timestamp(new Date().getTime())); . . . ps.setTimestamp(14, myobject.getLastUpdate()); . . . int rowsUpdated = ps.executeUpdate();
Cheers! Kevin
-----Original Message----- From: David Barron [mailto:Davi...@sas.com] Sent: Friday, August 20, 2004 1:41 PM To: ja...@lists.mysql.com Subject: PreparedStatement.setDate problem
I'm trying to update a record and I'm using a PreparedStatement to do it. One of the fields is a Date field, the rest are varchar fields of various lengths. When I do the executeUpdate method all of the varchar fields are updated but the date field is not. There are no errors at all, but the date field does not change. Is this a bug perhaps?
-- MySQL Java Mailing List For list archives: http://lists.mysql.com/java To unsubscribe: http://lists.mysql.com/java?unsub=kev...@stepup.com




