Skip site navigation (1) Skip section navigation (2)

My Bug report: JDBC-Driver produces wrong output.

From: Jan Thomae <jan(at)smb-tec(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: My Bug report: JDBC-Driver produces wrong output.
Date: 2000-11-02 10:56:06
Message-ID: 00110212025700.00451@ramses (view raw or flat)
Thread:
Lists: pgsql-bugs
Hi,

I had a look over the JDBC-Driver and was able to remove the bug. It seems,
that the formatting of the timestamp caused the malfunction. I'd like to send
you my modifications, since you might be interested in them:

File: ResultSet.java 
Directory: src/interfaces/jdbc/org/postgresql/jdbc2 

  public Timestamp getTimestamp(int columnIndex) throws SQLException
  {
    String s = getString(columnIndex);

    if(s==null)
	return null;
    
    // This works, but it's commented out because Michael Stephenson's
    // solution is better still:
    // SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

// Modification by Jan Thomae
    String sub = s.substring(s.length() - 3, s.length()-2);
    if (sub.equals("+") || sub.equals("-")) {
        s = s.substring(0, s.length()-3) + "GMT"+ s.substring(s.length()-3, s.length())+":00";
    }
// -------
    // Michael Stephenson's solution:
    SimpleDateFormat df = null;

// Modification by Jan Thomae
    if (s.length()>27) {
    df = new SimpleDateFormat("yyyy-MM-dd HH:mm:sszzzzzzzzz");  
    } else        
// -------
    if (s.length()>21 && s.indexOf('.') != -1) {
    df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSzzz");
    } else if (s.length()>19 && s.indexOf('.') == -1) {
	df = new SimpleDateFormat("yyyy-MM-dd HH:MM:sszzz");
    } else if (s.length()>19 && s.indexOf('.') != -1) {
	df = new SimpleDateFormat("yyyy-MM-dd HH:MM:ss.SS");
    } else if (s.length()>10 && s.length()<=18) {
	df = new SimpleDateFormat("yyyy-MM-dd HH:MM:ss");
    } else {
	df = new SimpleDateFormat("yyyy-MM-dd");
    }
    
    try {
	return new Timestamp(df.parse(s).getTime());
    } catch(ParseException e) {
	throw new PSQLException("postgresql.res.badtimestamp",new Integer(e.getErrorOffset()),s);
    }
  }

Best regards,
Jan Thomae

--
____________________________________________________________________
Jan Thomae		                            jan(at)smb-tec(dot)com
SMB GmbH		                     http://www.smb-tec.com




Responses

pgsql-bugs by date

Next:From: pgsql-bugsDate: 2000-11-02 12:21:56
Subject: LIKE(~~) OR regular pattern(~) deliver incomplete output
Previous:From: pgsql-bugsDate: 2000-11-02 09:34:08
Subject: JDBC-Driver produces wrong output.

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group