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: Ttransacted.java 3313 2003-09-17 08:56:40Z durieuxp $
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 Ttransacted {
35:
36: static DataSource dataSource = null;
37:
38: /**
39: * Entry point
40: */
41: public static void init() throws NamingException, RemoteException {
42:
43: // Get DataSource
44: dataSource = DBEnvSL.getDataSource("jdbc_1");
45:
46: // create tables
47: createTable("transactedSimpleEB");
48: createTable("transactedSimpleEC");
49: }
50:
51: /**
52: * create a table
53: */
54: private static void createTable(String name) throws RemoteException {
55:
56: // get connection
57: Connection conn = null;
58: try {
59: conn = dataSource.getConnection();
60: } catch (Exception e) {
61: throw new RemoteException("Cannot get Connection");
62: }
63:
64: Statement stmt;
65: try {
66: stmt = conn.createStatement();
67: stmt.execute("DROP TABLE " + name);
68: stmt.close();
69: } catch (Exception e) {
70: }
71: try {
72: stmt = conn.createStatement();
73: stmt
74: .execute("create table "
75: + name
76: + "(c_accno varchar(12) not null primary key,"
77: + "c_customer varchar(20), c_balance integer, c_ident integer, c_count integer )");
78: stmt.execute("insert into " + name
79: + " values('pk1', 'NotSupported', 4, 0, 0)");
80: stmt.execute("insert into " + name
81: + " values('pk2', 'Required', 8, 0, 0)");
82: stmt.execute("insert into " + name
83: + " values('pk3', 'Never', 16, 0, 0)");
84: stmt.execute("insert into " + name
85: + " values('pk4', 'RequiresNew', 32, 0, 0)");
86: stmt.execute("insert into " + name
87: + " values('pk5', 'Mandatory', 64, 0, 0)");
88: stmt.execute("insert into " + name
89: + " values('pk6', 'Supports', 128, 0, 0)");
90: stmt.close();
91: conn.close(); // release connection
92: } catch (Exception e) {
93: System.err.println("Exception in createTable : " + e);
94: throw new RemoteException("Exception in createTable : " + e);
95: }
96: }
97:
98: }
|