Yes, I agree but I am outputting from a database table using a preparedstatement such as select * from tablename. If the date is a
string in the column then there are no problems and simpledateformat works but when the date column is of the type timestamp then simpledate format has no effect. The code I have is below:
PreparedStatement ps22 = connection.prepareStatement("SELECT Date, Balance FROM Purse");
rs1 = ps22.executeQuery();
while (rs1.next()){
try {
TimeZone gmt = TimeZone.getTimeZone("GMT+1");
GregorianCalendar in = new GregorianCalendar(gmt);
SimpleDateFormat sdf = new SimpleDateFormat( "dd MMM yyyy hh:mm:ss" );
sdf.setCalendar(in);
String theDate = sdf.format(in.getTime());
try {
Date date = sdf.parse(theDate);
in.setTime(date);
java.sql.Timestamp sDate = new java.sql.Timestamp(date.getTime());
int dep = 0;
String pname = "Lunar Telecoms Ltd";
String bal = rs1.getString("Balance");
PreparedStatement psi1 = connection.prepareStatement("INSERT INTO Account " +
"VALUES (?, ?, ?, ?, ?)");
psi1.setTimestamp(1,sDate);
psi1.setString(2,pname);
psi1.setInt(3,dep);
psi1.setString(4,s);
psi1.setString(5,bal);
psi1.executeUpdate();
psi1.close();
Any ideas why this outputs the date column as a timestamp and not like I wanted it (dd MMM yyyy hh:mm:ss) ???
Any help is much appreciated.
Suhail
Originally posted by Jamie Robertson:
Timestamps are not used for formatting. Use the SimpleDateFormat class to make the timestamp appear as you want:
http://java.sun.com/j2se/1.3/docs/api/java/text/SimpleDateFormat.html
Jamie