This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Hi, I was wondering if anyone knew how to modify the timestamp data type so that it output like: DD MMM YYYY HH:NN:SS Has anyone done this? I tried to modify Timestamp.java in the java.sql directory but its a bit messy. Basically when I output a table using select * from tablename I get the date in the usual timestamp format and it doesn't look as nice as the format i'd like. Any ideas are welcome. Suhail
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