KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > ftables > Tfannuaire


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:
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.ftables;
27
28 import java.rmi.RemoteException JavaDoc;
29 import java.sql.Connection JavaDoc;
30 import java.sql.Statement JavaDoc;
31 import javax.naming.NamingException JavaDoc;
32 import javax.sql.DataSource JavaDoc;
33 //import org.objectweb.jonas.common.Log;
34
//import org.objectweb.util.monolog.api.Logger;
35
//import org.objectweb.util.monolog.api.BasicLevel;
36

37 public class Tfannuaire extends Tmanager {
38
39     /**
40      * Entry point
41      */

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

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