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: Tmessage.java 2478 2003-06-03 14:51:46Z 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 Tmessage {
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("messageMRecordEC");
48: }
49:
50: /**
51: * create a table
52: */
53: private static void createTable(String name) throws RemoteException {
54:
55: // get connection
56: 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: } catch (Exception e) {
69: }
70: try {
71: stmt = conn.createStatement();
72: stmt
73: .execute("create table "
74: + name
75: + "(c_uuid varchar(20) not null, c_dest varchar(30), c_value integer, c_mdb varchar(30) not null,"
76: + "primary key (c_uuid, c_mdb))");
77: stmt.close();
78: conn.close(); // release connection
79: } catch (Exception e) {
80: System.err.println("Exception in createTable : " + e);
81: throw new RemoteException("Exception in createTable : " + e);
82: }
83: }
84:
85: }
|