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