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.util.monolog.api.BasicLevel; 35 36 40 public class Tomu extends Tmanager { 41 42 45 public static void init() throws NamingException , RemoteException { 46 mgrInit(); 47 createTableA(); 48 createTableB(); 49 } 50 51 54 private static void createTableA() throws RemoteException { 55 56 String name = "JT2_OMU_A"; 57 58 Connection conn = null; 60 try { 61 conn = dataSource.getConnection(); 62 } catch(Exception e) { 63 throw new RemoteException ("Cannot get Connection"); 64 } 65 66 Statement stmt; 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 stmt = conn.createStatement(); 77 stmt.execute("create table " + name + 78 "( c_ida varchar(30) not null primary key )"); 79 stmt.close(); 80 conn.close(); } catch(Exception e) { 82 logger.log(BasicLevel.ERROR, "Exception in createTable : "+e); 83 throw new RemoteException ("Exception in createTable : "+e); 84 } 85 logger.log(BasicLevel.INFO, "Table "+name+" created"); 86 } 87 88 91 private static void createTableB() throws RemoteException { 92 93 String name = "JT2_OMU_B"; 94 95 Connection conn = null; 97 try { 98 conn = dataSource.getConnection(); 99 } catch(Exception e) { 100 throw new RemoteException ("Cannot get Connection"); 101 } 102 103 Statement stmt; 104 try { 105 stmt = conn.createStatement(); 106 stmt.execute("DROP TABLE " + name); 107 stmt.close(); 108 logger.log(BasicLevel.INFO, "Table "+name+" dropped"); 109 } catch(Exception e) { 110 logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"+e); 111 } 112 try { 113 stmt = conn.createStatement(); 114 stmt.execute("create table " + name + 115 "( c_idb varchar(30) not null primary key, cfk_ida varchar(30) )"); 116 stmt.close(); 117 conn.close(); } catch(Exception e) { 119 logger.log(BasicLevel.ERROR, "Exception in createTable : "+e); 120 throw new RemoteException ("Exception in createTable : "+e); 121 } 122 logger.log(BasicLevel.INFO, "Table "+name+" created"); 123 } 124 125 } 126 | Popular Tags |