Re: My Bug report: JDBC-Driver produces wrong output.]

Bruce Momjian <pgman@candle.pha.pa.us>

From: Bruce Momjian <pgman@candle.pha.pa.us>
To: Jan Thomae <jan@smb-tec.com>
Cc: pgsql-bugs@postgresql.org
Date: 2000-11-04T16:38:48Z
Lists: pgsql-bugs
I think this is fixed in the current cvs tree.  Can you grab a snapshot
ftp file and let me know.  If not, can I get a contect diff.  Thanks.


> 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@smb-tec.com
> SMB GmbH		                     http://www.smb-tec.com
> 
> 
> 
> 


-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026