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 Tcluster extends Tmanager { 37 38 41 public static void init() throws NamingException , RemoteException { 42 mgrInit(); 43 createTable("clusterIdentityEC"); 44 } 45 46 50 private static void createTable(String name) throws RemoteException { 51 52 Connection conn = null; 54 try { 55 conn = dataSource.getConnection(); 56 } catch(Exception e) { 57 throw new RemoteException ("Cannot get Connection"); 58 } 59 60 Statement stmt; 61 try { 62 stmt = conn.createStatement(); 63 stmt.execute("DROP TABLE "+name); 64 stmt.close(); 65 logger.log(BasicLevel.INFO, "Table "+name+" dropped"); 66 } catch(Exception e) { 67 logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"+e); 68 } 69 try { 70 stmt = conn.createStatement(); 71 stmt.execute("create table " + name + 72 "(c_name varchar(30) not null primary key,"+ 73 "c_number integer )"); 74 stmt.execute("insert into "+name+" values('name1', 1000)"); 75 stmt.execute("insert into "+name+" values('name2', 1000)"); 76 stmt.execute("insert into "+name+" values('name3', 1000)"); 77 stmt.execute("insert into "+name+" values('name11', 5000)"); 78 stmt.execute("insert into "+name+" values('name12', 5000)"); 79 stmt.execute("insert into "+name+" values('name13', 5000)"); 80 81 stmt.close(); 82 conn.close(); } catch(Exception e) { 84 logger.log(BasicLevel.ERROR, "Exception in createTable : "+e); 85 throw new RemoteException ("Exception in createTable : "+e); 86 } 87 logger.log(BasicLevel.INFO, "Table "+name+" created"); 88 } 89 90 } 91 | Popular Tags |