001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: Tannuaire.java 4406 2004-03-19 11:57:20Z benoitf $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.tables;
027:
028: import java.rmi.RemoteException;
029: import java.sql.Connection;
030: import java.sql.Statement;
031:
032: import javax.naming.NamingException;
033:
034: import org.objectweb.util.monolog.api.BasicLevel;
035:
036: public class Tannuaire extends Tmanager {
037:
038: /**
039: * Entry point
040: */
041: public static void init() throws NamingException, RemoteException {
042: mgrInit();
043: createTable("annuairePersonneEC");
044: }
045:
046: /**
047: * create a table for CMP 1.x
048: */
049: private static void createTable(String name) throws RemoteException {
050:
051: // get connection
052: Connection conn = null;
053: try {
054: conn = dataSource.getConnection();
055: } catch (Exception e) {
056: throw new RemoteException("Cannot get Connection");
057: }
058:
059: Statement stmt;
060: try {
061: stmt = conn.createStatement();
062: stmt.execute("DROP TABLE " + name);
063: stmt.close();
064: logger.log(BasicLevel.INFO, "Table " + name + " dropped");
065: } catch (Exception e) {
066: logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"
067: + e);
068: }
069: try {
070: stmt = conn.createStatement();
071: stmt
072: .execute("create table "
073: + name
074: + "(c_nom varchar(30) not null primary key,"
075: + "c_numero varchar(10), c_ident integer, c_count integer)");
076: stmt.execute("insert into " + name
077: + " values('Philippe Coq', '1235456', 0, 0)");
078: stmt.execute("insert into " + name
079: + " values('Philippe Durieux', '638', 0, 0)");
080: stmt.execute("insert into " + name
081: + " values('Adriana Danes', '1233456', 0, 0)");
082: stmt.execute("insert into " + name
083: + " values('Helene Joanin', '1230456', 0, 0)");
084: stmt.execute("insert into " + name
085: + " values('Gerard Vandome', '1232456', 0, 0)");
086: stmt.execute("insert into " + name
087: + " values('Francois Exertier', '1323456', 0, 0)");
088: stmt.execute("insert into " + name
089: + " values('Emmanuel Facarde', '1234356', 0, 0)");
090: stmt.execute("insert into " + name
091: + " values('Charly Mingus', '1238456', 0, 0)");
092: stmt.execute("insert into " + name
093: + " values('Thelonious Monk', '1239456', 0, 0)");
094: stmt.execute("insert into " + name
095: + " values('Jean-Luc Richard', '1203456', 0, 0)");
096: stmt.close();
097: conn.close(); // release connection
098: } catch (Exception e) {
099: logger.log(BasicLevel.ERROR,
100: "Exception in createTable : \n" + e);
101: throw new RemoteException("Exception in createTable : " + e);
102: }
103: logger.log(BasicLevel.INFO, "Table " + name + " created");
104: }
105:
106: }
|