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 41 public class Tbytearray extends Tmanager { 42 43 46 public static void init() throws NamingException , RemoteException { 47 mgrInit(); 48 createTable("JT_EtypeByteArrayEC"); 49 } 50 51 54 private static void createTable(String name) throws RemoteException { 55 56 Connection conn = null; 58 try { 59 conn = dataSource.getConnection(); 60 } catch(Exception e) { 61 throw new RemoteException ("Cannot get Connection"); 62 } 63 64 Statement stmt; 65 try { 66 stmt = conn.createStatement(); 67 stmt.execute("DROP TABLE "+name); 68 stmt.close(); 69 logger.log(BasicLevel.INFO, "Table "+name+" dropped"); 70 } catch(Exception e) { 71 logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"+e); 72 } 73 try { 74 int dbType = Env.getDatabaseType(conn); 75 String cTypeName; 76 switch (dbType) { 77 case Env.DB_ORACLE: cTypeName = "raw(256)"; break; 78 case Env.DB_POSGRESQL: cTypeName = "bytea"; break; 79 case Env.DB_DB2: cTypeName = "varchar(128) for bit data"; break; 80 case Env.DB_MYSQL: cTypeName = "blob"; break; 81 default: cTypeName = "varbinary"; } 83 stmt = conn.createStatement(); 84 stmt.execute("create table " + name + 85 "( c_pk varchar(30) not null primary key, c_f1 "+cTypeName+")"); 86 87 stmt.close(); 88 conn.close(); } catch(Exception e) { 90 logger.log(BasicLevel.ERROR, "Exception in createTable : "+e); 91 throw new RemoteException ("Exception in createTable : "+e); 92 } 93 logger.log(BasicLevel.INFO, "Table "+name+" created"); 94 } 95 96 } 97 | Popular Tags |