1 25 26 package org.objectweb.jonas.jtests.tables; 27 28 import java.rmi.RemoteException ; 29 import java.sql.Connection ; 30 import java.sql.Date ; 31 import java.sql.PreparedStatement ; 32 import java.sql.Statement ; 33 34 import javax.naming.NamingException ; 35 36 import org.objectweb.util.monolog.api.BasicLevel; 37 38 42 public class Tosqldate extends Tmanager { 43 44 47 public static void init() throws NamingException , RemoteException { 48 mgrInit(); 49 createTable("JT_EtypeOsqldateEC"); 50 } 51 52 55 private static void createTable(String name) throws RemoteException { 56 57 Connection conn = null; 59 try { 60 conn = dataSource.getConnection(); 61 } catch(Exception e) { 62 throw new RemoteException ("Cannot get Connection"); 63 } 64 65 Statement stmt; 66 PreparedStatement pStmt; 67 try { 68 stmt = conn.createStatement(); 69 stmt.execute("DROP TABLE "+name); 70 stmt.close(); 71 logger.log(BasicLevel.INFO, "Table "+name+" dropped"); 72 } catch(Exception e) { 73 logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"+e); 74 } 75 try { 76 String cTypeName = "date"; stmt = conn.createStatement(); 78 stmt.execute("create table " + name + 79 "( c_pk varchar(30) not null primary key, c_f1 "+cTypeName+")"); 80 stmt.close(); 81 pStmt = conn.prepareStatement("insert into "+name+" values('pk1', ?)"); 82 pStmt.setDate(1, Date.valueOf("1970-01-01")); 83 pStmt.executeUpdate(); 84 pStmt.close(); 85 pStmt = conn.prepareStatement("insert into "+name+" values('pk2', ?)"); 86 pStmt.setDate(1, Date.valueOf("1970-01-02")); 87 pStmt.executeUpdate(); 88 pStmt.close(); 89 pStmt = conn.prepareStatement("insert into "+name+" values('pk3', ?)"); 90 pStmt.setDate(1, Date.valueOf("1970-01-03")); 91 pStmt.executeUpdate(); 92 pStmt.close(); 93 pStmt = conn.prepareStatement("insert into "+name+" values('pk4', ?)"); 94 pStmt.setDate(1, Date.valueOf("1970-01-04")); 95 pStmt.executeUpdate(); 96 pStmt.close(); 97 pStmt = conn.prepareStatement("insert into "+name+" values('pk5', ?)"); 98 pStmt.setDate(1, Date.valueOf("1970-01-05")); 99 pStmt.executeUpdate(); 100 pStmt.close(); 101 pStmt = conn.prepareStatement("insert into "+name+" values('pk5bis', ?)"); 102 pStmt.setDate(1, Date.valueOf("1970-01-05")); 103 pStmt.executeUpdate(); 104 pStmt.close(); 105 pStmt = conn.prepareStatement("insert into "+name+" values('pktoremove', ?)"); 106 pStmt.setDate(1, Date.valueOf("1970-01-12")); 107 pStmt.executeUpdate(); 108 pStmt.close(); 109 pStmt = conn.prepareStatement("insert into "+name+" values('pknull', NULL)"); 110 pStmt.executeUpdate(); 111 pStmt.close(); 112 pStmt = conn.prepareStatement("insert into "+name+" values('pkchangenull', ?)"); 113 pStmt.setDate(1, Date.valueOf("1970-01-12")); 114 pStmt.executeUpdate(); 115 pStmt.close(); 116 conn.close(); } catch(Exception e) { 118 logger.log(BasicLevel.ERROR, "Exception in createTable : "+e); 119 throw new RemoteException ("Exception in createTable : "+e); 120 } 121 logger.log(BasicLevel.INFO, "Table "+name+" created"); 122 } 123 124 } 125 | Popular Tags |