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 Tannuaire extends Tmanager { 37 38 41 public static void init() throws NamingException , RemoteException { 42 mgrInit(); 43 createTable("annuairePersonneEC"); 44 } 45 46 49 private static void createTable(String name) throws RemoteException { 50 51 Connection conn = null; 53 try { 54 conn = dataSource.getConnection(); 55 } catch(Exception e) { 56 throw new RemoteException ("Cannot get Connection"); 57 } 58 59 Statement stmt; 60 try { 61 stmt = conn.createStatement(); 62 stmt.execute("DROP TABLE "+name); 63 stmt.close(); 64 logger.log(BasicLevel.INFO, "Table "+name+" dropped"); 65 } catch(Exception e) { 66 logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"+e); 67 } 68 try { 69 stmt = conn.createStatement(); 70 stmt.execute("create table " + name + 71 "(c_nom varchar(30) not null primary key,"+ 72 "c_numero varchar(10), c_ident integer, c_count integer)"); 73 stmt.execute("insert into "+name+" values('Philippe Coq', '1235456', 0, 0)"); 74 stmt.execute("insert into "+name+" values('Philippe Durieux', '638', 0, 0)"); 75 stmt.execute("insert into "+name+" values('Adriana Danes', '1233456', 0, 0)"); 76 stmt.execute("insert into "+name+" values('Helene Joanin', '1230456', 0, 0)"); 77 stmt.execute("insert into "+name+" values('Gerard Vandome', '1232456', 0, 0)"); 78 stmt.execute("insert into "+name+" values('Francois Exertier', '1323456', 0, 0)"); 79 stmt.execute("insert into "+name+" values('Emmanuel Facarde', '1234356', 0, 0)"); 80 stmt.execute("insert into "+name+" values('Charly Mingus', '1238456', 0, 0)"); 81 stmt.execute("insert into "+name+" values('Thelonious Monk', '1239456', 0, 0)"); 82 stmt.execute("insert into "+name+" values('Jean-Luc Richard', '1203456', 0, 0)"); 83 stmt.close(); 84 conn.close(); } catch(Exception e) { 86 logger.log(BasicLevel.ERROR, "Exception in createTable : \n"+e); 87 throw new RemoteException ("Exception in createTable : "+e); 88 } 89 logger.log(BasicLevel.INFO, "Table "+name+" created"); 90 } 91 92 } 93 94 95 | Popular Tags |