(file) Return to DefaultSqlFormatter.java CVS log (file) (dir) Up to [Development] / ifodder / src / com / javaunderground / jdbc

 1 pjaol 1.1 
 2           /**
 3            * Title:        <p>
 4            * Description:  <p>
 5            * Copyright:    Copyright (c) Troy Thompson, Bob Byron<p>
 6            * Company:      JavaUnderground<p>
 7            * @author       Troy Thompson, Bob Byron
 8            * @version 1.1
 9            */
10           package com.javaunderground.jdbc;
11           
12           import java.util.Calendar;
13           import java.math.BigDecimal;
14           import java.io.*;
15           import java.sql.*;
16           
17           public class DefaultSqlFormatter extends SqlFormatter {
18           
19             final String ymd24="'YYYY-MM-DD HH24:MI:SS.#'";
20           
21             private String format(Calendar cal){
22 pjaol 1.1     return "TO_DATE('" + new java.sql.Timestamp(cal.getTime().getTime()) + "',"+ymd24+")";
23             }
24           
25             private String format(java.sql.Date date){
26               return "TO_DATE('" + new java.sql.Timestamp(date.getTime()) + "',"+ymd24+")";
27             }
28           
29             private String format(java.sql.Time time){
30               Calendar cal = Calendar.getInstance();
31               cal.setTime(new java.util.Date(time.getTime()));
32               return "TO_DATE('" + cal.get(Calendar.HOUR_OF_DAY) + ":" +
33                 cal.get(Calendar.MINUTE) + ":" + cal.get(Calendar.SECOND) + "." +
34                 cal.get(Calendar.MILLISECOND) + "','HH24:MI:SS.#')";
35             }
36           
37             private String format(java.sql.Timestamp timestamp){
38               return "TO_DATE('" + timestamp.toString() + "','YYYY-MM-DD HH24:MI:SS.#')";
39             }
40           
41           
42           
43 pjaol 1.1   public String format(Object o) throws SQLException{
44               if (o == null)               return "NULL";
45               if (o instanceof Calendar)   return format((Calendar)o);
46               if (o instanceof Date)       return format((Date)o);
47               if (o instanceof Time)       return format((Time)o);
48               if (o instanceof Timestamp)  return format((Timestamp)o);
49               //if object not in one of our overridden methods, send to super class
50               return super.format(o);
51             }
52           }

cvsadmin
Powered by
ViewCVS 0.9.2