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 import javax.naming.NamingException ; 32 import javax.sql.DataSource ; 33 34 public class Tjdbcra { 35 36 static DataSource dataSource = null; 37 38 41 42 public static void init() throws NamingException , RemoteException { 43 44 dataSource = DBEnvSL.getDataSource("jdbc_xa1"); 46 47 createTable("JDBC_XA1"); 49 50 dataSource = null; 51 52 dataSource = DBEnvSL.getDataSource("jdbc_xa2"); 54 createTable("JDBC_XA2"); 55 56 dataSource = null; 57 } 58 59 62 private static void createTable(String name) throws RemoteException { 63 64 66 Connection conn = null; 67 68 try { 69 conn = dataSource.getConnection(); 70 } catch(Exception e) { 71 throw new RemoteException ("Cannot get Connection"); 72 } 73 74 Statement stmt; 75 76 try { 77 stmt = conn.createStatement(); 78 stmt.execute("DROP TABLE "+name); 79 stmt.close(); 80 } catch(Exception e) { 81 System.err.println("Exception in dropTable : \n"+e); 82 } 83 84 try { 85 stmt = conn.createStatement(); 86 stmt.execute("create table " + name + 87 "(xa_accno integer not null primary key,"+ 88 "xa_customer varchar(20), xa_balance float )"); 89 stmt.close(); 90 conn.close(); 91 } catch(Exception e) { 92 System.err.println("Exception in createTable : \n"+e); 93 throw new RemoteException ("Exception in createTable : "+e); 94 } 95 } 96 } 97 98 99 | Popular Tags |