01: /*
02: * JOnAS: Java(TM) Open Application Server
03: * Copyright (C) 1999 Bull S.A.
04: * Contact: jonas-team@objectweb.org
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19: * USA
20: *
21: * --------------------------------------------------------------------------
22: * $Id: Tjdbcra.java 3608 2003-10-28 00:43:30Z tonyortiz $
23: * --------------------------------------------------------------------------
24: */
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: /**
39: * Entry point
40: */
41:
42: public static void init() throws NamingException, RemoteException {
43:
44: // Get DataSource
45: dataSource = DBEnvSL.getDataSource("jdbc_xa1");
46:
47: // create first table
48: createTable("JDBC_XA1");
49:
50: dataSource = null;
51:
52: // create second table
53: dataSource = DBEnvSL.getDataSource("jdbc_xa2");
54: createTable("JDBC_XA2");
55:
56: dataSource = null;
57: }
58:
59: /**
60: * create a table
61: */
62: private static void createTable(String name) throws RemoteException {
63:
64: // get connection
65:
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: }
|