KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > tables > Tannuaire


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * 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: Tannuaire.java,v 1.10 2004/03/19 11:57:15 benoitf Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.tables;
27
28 import java.rmi.RemoteException JavaDoc;
29 import java.sql.Connection JavaDoc;
30 import java.sql.Statement JavaDoc;
31
32 import javax.naming.NamingException JavaDoc;
33
34 import org.objectweb.util.monolog.api.BasicLevel;
35
36 public class Tannuaire extends Tmanager {
37
38     /**
39      * Entry point
40      */

41     public static void init() throws NamingException JavaDoc, RemoteException JavaDoc {
42     mgrInit();
43     createTable("annuairePersonneEC");
44     }
45
46     /**
47      * create a table for CMP 1.x
48      */

49     private static void createTable(String JavaDoc name) throws RemoteException JavaDoc {
50
51     // get connection
52
Connection JavaDoc conn = null;
53     try {
54         conn = dataSource.getConnection();
55     } catch(Exception JavaDoc e) {
56         throw new RemoteException JavaDoc("Cannot get Connection");
57     }
58     
59     Statement JavaDoc stmt;
60     try {
61         stmt = conn.createStatement();
62         stmt.execute("DROP TABLE "+name);
63         stmt.close();
64         logger.log(BasicLevel.INFO, "Table "+name+" dropped");
65     } catch(Exception JavaDoc e) {
66         logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"+e);
67     }
68     try {
69         stmt = conn.createStatement();
70         stmt.execute("create table " + name +
71              "(c_nom varchar(30) not null primary key,"+
72              "c_numero varchar(10), c_ident integer, c_count integer)");
73         stmt.execute("insert into "+name+" values('Philippe Coq', '1235456', 0, 0)");
74         stmt.execute("insert into "+name+" values('Philippe Durieux', '638', 0, 0)");
75         stmt.execute("insert into "+name+" values('Adriana Danes', '1233456', 0, 0)");
76         stmt.execute("insert into "+name+" values('Helene Joanin', '1230456', 0, 0)");
77         stmt.execute("insert into "+name+" values('Gerard Vandome', '1232456', 0, 0)");
78         stmt.execute("insert into "+name+" values('Francois Exertier', '1323456', 0, 0)");
79         stmt.execute("insert into "+name+" values('Emmanuel Facarde', '1234356', 0, 0)");
80         stmt.execute("insert into "+name+" values('Charly Mingus', '1238456', 0, 0)");
81         stmt.execute("insert into "+name+" values('Thelonious Monk', '1239456', 0, 0)");
82         stmt.execute("insert into "+name+" values('Jean-Luc Richard', '1203456', 0, 0)");
83         stmt.close();
84         conn.close(); // release connection
85
} catch(Exception JavaDoc e) {
86         logger.log(BasicLevel.ERROR, "Exception in createTable : \n"+e);
87         throw new RemoteException JavaDoc("Exception in createTable : "+e);
88     }
89     logger.log(BasicLevel.INFO, "Table "+name+" created");
90     }
91
92 }
93
94
95
Popular Tags