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 public class Tbmt extends Tmanager { 37 38 41 public static void init() throws NamingException , RemoteException { 42 mgrInit(); 43 createTable(); 44 } 45 46 private static void createTable() throws RemoteException { 47 48 String name = "JT2_BMT"; 49 50 Connection conn = null; 52 try { 53 conn = dataSource.getConnection(); 54 } catch(Exception e) { 55 throw new RemoteException ("Cannot get Connection"); 56 } 57 58 Statement stmt; 59 try { 60 stmt = conn.createStatement(); 61 stmt.execute("DROP TABLE "+name); 62 stmt.close(); 63 logger.log(BasicLevel.INFO, "Table "+name+" dropped"); 64 } catch(Exception e) { 65 logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"+e); 66 } 67 try { 68 stmt = conn.createStatement(); 69 stmt.execute("create table " + name + 70 "(IDMAR integer not null primary key, NOM varchar(30))"); 71 stmt.execute("insert into "+name+" values(0, 'Philippe Coq')"); 72 stmt.execute("insert into "+name+" values(1, 'Philippe Durieux')"); 73 stmt.execute("insert into "+name+" values(2, 'Adriana Danes')"); 74 stmt.execute("insert into "+name+" values(3, 'Helene Joanin')"); 75 stmt.close(); 76 conn.close(); 77 } catch(Exception e) { 78 logger.log(BasicLevel.ERROR, "Exception in createTable : \n"+e); 79 throw new RemoteException ("Exception in createTable : "+e); 80 } 81 logger.log(BasicLevel.INFO, "Table "+name+" created"); 82 } 83 84 } 85 86 87 | Popular Tags |