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 Toshort extends Tmanager { 41 42 45 public static void init() throws NamingException , RemoteException { 46 mgrInit(); 47 createTable("JT_EtypeOshortEC"); 48 } 49 50 53 private static void createTable(String name) throws RemoteException { 54 55 Connection conn = null; 57 try { 58 conn = dataSource.getConnection(); 59 } catch(Exception e) { 60 throw new RemoteException ("Cannot get Connection"); 61 } 62 63 Statement stmt; 64 try { 65 stmt = conn.createStatement(); 66 stmt.execute("DROP TABLE "+name); 67 stmt.close(); 68 logger.log(BasicLevel.INFO, "Table "+name+" dropped"); 69 } catch(Exception e) { 70 logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"+e); 71 } 72 try { 73 String cTypeName = "smallint"; stmt = conn.createStatement(); 75 stmt.execute("create table " + name + 76 "( c_pk varchar(30) not null primary key, c_f1 "+cTypeName+")"); 77 stmt.execute("insert into "+name+" values('pk1', 1)"); 78 stmt.execute("insert into "+name+" values('pk2', 2)"); 79 stmt.execute("insert into "+name+" values('pk3', 3)"); 80 stmt.execute("insert into "+name+" values('pk4', 4)"); 81 stmt.execute("insert into "+name+" values('pk5', 5)"); 82 stmt.execute("insert into "+name+" values('pk5bis', 5)"); 83 stmt.execute("insert into "+name+" values('pktoremove', 10000)"); 84 stmt.execute("insert into "+name+" values('pknull', NULL)"); 85 stmt.execute("insert into "+name+" values('pkchangenull', 10000)"); 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 |