1 25 26 package org.objectweb.jonas.jtests.tables; 27 28 import java.rmi.RemoteException ; 29 import java.sql.Connection ; 30 import java.sql.Statement ; 31 32 import javax.naming.NamingException ; 33 34 import org.objectweb.jonas.jtests.util.Env; 35 import org.objectweb.util.monolog.api.BasicLevel; 36 37 38 42 public class Todouble extends Tmanager { 43 44 47 public static void init() throws NamingException , RemoteException { 48 mgrInit(); 49 createTable("JT_EtypeOdoubleEC"); 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 try { 67 stmt = conn.createStatement(); 68 stmt.execute("DROP TABLE "+name); 69 stmt.close(); 70 logger.log(BasicLevel.INFO, "Table "+name+" dropped"); 71 } catch(Exception e) { 72 logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"+e); 73 } 74 try { 75 int dbType = Env.getDatabaseType(conn); 76 String cTypeName; 77 if ((dbType==Env.DB_ORACLE) || (dbType==Env.DB_POSGRESQL)) { 78 cTypeName = "double precision"; 79 } else { 80 cTypeName = "double"; 82 } 83 stmt = conn.createStatement(); 84 stmt.execute("create table " + name + 85 "( c_pk varchar(30) not null primary key, c_f1 "+cTypeName+")"); 86 stmt.execute("insert into "+name+" values('pk1', 1.0)"); 87 stmt.execute("insert into "+name+" values('pk2', 2.0)"); 88 stmt.execute("insert into "+name+" values('pk3', 3.0)"); 89 stmt.execute("insert into "+name+" values('pk4', 4.0)"); 90 stmt.execute("insert into "+name+" values('pk5', 5.0)"); 91 stmt.execute("insert into "+name+" values('pk5bis', 5.0)"); 92 stmt.execute("insert into "+name+" values('pktoremove', 10000.0)"); 93 stmt.execute("insert into "+name+" values('pknull', NULL)"); 94 stmt.execute("insert into "+name+" values('pkchangenull', 1.0)"); 95 96 stmt.close(); 97 conn.close(); } catch(Exception e) { 99 logger.log(BasicLevel.ERROR, "Exception in create/init Table : "+e); 100 throw new RemoteException ("Exception in create/init Table : "+e); 101 } 102 logger.log(BasicLevel.INFO, "Table "+name+" created"); 103 } 104 105 } 106 | Popular Tags |