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: Tbmt.java 4673 2004-04-30 14:26:29Z 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:
32: import javax.naming.NamingException;
33:
34: import org.objectweb.util.monolog.api.BasicLevel;
35:
36: public class Tbmt extends Tmanager {
37:
38: /**
39: * Entry point
40: */
41: public static void init() throws NamingException, RemoteException {
42: mgrInit();
43: createTable();
44: }
45:
46: private static void createTable() throws RemoteException {
47:
48: String name = "JT2_BMT";
49:
50: // get connection
51: Connection conn = null;
52: try {
53: conn = dataSource.getConnection();
54: } catch (Exception e) {
55: throw new RemoteException("Cannot get Connection");
56: }
57:
58: Statement stmt;
59: try {
60: stmt = conn.createStatement();
61: stmt.execute("DROP TABLE " + name);
62: stmt.close();
63: logger.log(BasicLevel.INFO, "Table " + name + " dropped");
64: } catch (Exception e) {
65: logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"
66: + e);
67: }
68: try {
69: stmt = conn.createStatement();
70: stmt
71: .execute("create table "
72: + name
73: + "(IDMAR integer not null primary key, NOM varchar(30))");
74: stmt.execute("insert into " + name
75: + " values(0, 'Philippe Coq')");
76: stmt.execute("insert into " + name
77: + " values(1, 'Philippe Durieux')");
78: stmt.execute("insert into " + name
79: + " values(2, 'Adriana Danes')");
80: stmt.execute("insert into " + name
81: + " values(3, 'Helene Joanin')");
82: stmt.close();
83: conn.close();
84: } catch (Exception e) {
85: logger.log(BasicLevel.ERROR,
86: "Exception in createTable : \n" + e);
87: throw new RemoteException("Exception in createTable : " + e);
88: }
89: logger.log(BasicLevel.INFO, "Table " + name + " created");
90: }
91:
92: }
|