Index: AbstractJdbc1ResultSet.java =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java,v retrieving revision 1.7.2.1 diff -C10 -r1.7.2.1 AbstractJdbc1ResultSet.java *** AbstractJdbc1ResultSet.java 2003/01/14 09:15:35 1.7.2.1 --- AbstractJdbc1ResultSet.java 2003/02/28 17:27:00 *************** *** 34,53 **** --- 34,59 ---- protected SQLWarning warnings = null; // The warning chain protected boolean wasNullFlag = false; // the flag for wasNull() // We can chain multiple resultSets together - this points to // next resultSet in the chain. protected ResultSet next = null; protected StringBuffer sbuf = null; public byte[][] rowBuffer = null; + protected static final SimpleDateFormat tsFormat = + new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss"); + protected static final SimpleDateFormat tstzFormat = + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); + protected static final SimpleDateFormat dateFormat = + new SimpleDateFormat("yyyy-MM-dd"); public AbstractJdbc1ResultSet(org.postgresql.PGConnection conn, Statement statement, Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) { this.connection = conn; this.statement = statement; this.fields = fields; this.rows = tuples; this.status = status; this.updateCount = updateCount; this.insertOID = insertOID; *************** *** 947,1023 **** rs.sbuf.append(" GMT"); rs.sbuf.append(c); rs.sbuf.append(s.substring(i, slen)); // Lastly, if the tz part doesn't specify the :MM part then // we add ":00" for java. if (slen - i < 5) rs.sbuf.append(":00"); // we'll use this dateformat string to parse the result. ! df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); } else { // Just found fractional seconds but no timezone. //If timestamptz then we use GMT, else local timezone if (pgDataType.equals("timestamptz")) { rs.sbuf.append(" GMT"); ! df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); } else { ! df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); } } } else if (slen == 19) { // No tz or fractional second info. //If timestamptz then we use GMT, else local timezone if (pgDataType.equals("timestamptz")) { rs.sbuf.append(" GMT"); ! df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); } else { ! df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); } } else { if (slen == 8 && s.equals("infinity")) //java doesn't have a concept of postgres's infinity //so set to an arbitrary future date s = "9999-01-01"; if (slen == 9 && s.equals("-infinity")) //java doesn't have a concept of postgres's infinity //so set to an arbitrary old date s = "0001-01-01"; // We must just have a date. This case is // needed if this method is called on a date // column ! df = new SimpleDateFormat("yyyy-MM-dd"); } try { // All that's left is to parse the string and return the ts. if ( org.postgresql.Driver.logDebug ) org.postgresql.Driver.debug("the data after parsing is " + rs.sbuf.toString() + " with " + nanos + " nanos"); ! Timestamp result = ! new Timestamp(df.parse(rs.sbuf.toString()).getTime()); result.setNanos(nanos); return result; } catch (ParseException e) { throw new PSQLException("postgresql.res.badtimestamp", new Integer(e.getErrorOffset()), s); } } } --- 953,1035 ---- rs.sbuf.append(" GMT"); rs.sbuf.append(c); rs.sbuf.append(s.substring(i, slen)); // Lastly, if the tz part doesn't specify the :MM part then // we add ":00" for java. if (slen - i < 5) rs.sbuf.append(":00"); // we'll use this dateformat string to parse the result. ! df = tstzFormat; } else { // Just found fractional seconds but no timezone. //If timestamptz then we use GMT, else local timezone if (pgDataType.equals("timestamptz")) { rs.sbuf.append(" GMT"); ! df = tstzFormat; } else { ! df = tsFormat; } } } else if (slen == 19) { // No tz or fractional second info. //If timestamptz then we use GMT, else local timezone if (pgDataType.equals("timestamptz")) { rs.sbuf.append(" GMT"); ! df = tstzFormat; } else { ! df = tsFormat; } } else { if (slen == 8 && s.equals("infinity")) //java doesn't have a concept of postgres's infinity //so set to an arbitrary future date s = "9999-01-01"; if (slen == 9 && s.equals("-infinity")) //java doesn't have a concept of postgres's infinity //so set to an arbitrary old date s = "0001-01-01"; // We must just have a date. This case is // needed if this method is called on a date // column ! df = dateFormat; } try { // All that's left is to parse the string and return the ts. if ( org.postgresql.Driver.logDebug ) org.postgresql.Driver.debug("the data after parsing is " + rs.sbuf.toString() + " with " + nanos + " nanos"); ! java.util.Date date = null; ! ! synchronized (df) ! { ! date = df.parse (rs.sbuf.toString ()); ! } ! ! Timestamp result = new Timestamp(date.getTime()); result.setNanos(nanos); return result; } catch (ParseException e) { throw new PSQLException("postgresql.res.badtimestamp", new Integer(e.getErrorOffset()), s); } } }