KickJava   Java API By Example, From Geeks To Geeks.

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


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: Tbmt.java,v 1.1 2004/04/30 14:26:29 durieuxp 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 Tbmt extends Tmanager {
37
38     /**
39      * Entry point
40      */

41     public static void init() throws NamingException JavaDoc, RemoteException JavaDoc {
42         mgrInit();
43         createTable();
44     }
45
46     private static void createTable() throws RemoteException JavaDoc {
47
48         String JavaDoc name = "JT2_BMT";
49
50         // get connection
51
Connection JavaDoc conn = null;
52         try {
53             conn = dataSource.getConnection();
54         } catch(Exception JavaDoc e) {
55             throw new RemoteException JavaDoc("Cannot get Connection");
56         }
57     
58         Statement JavaDoc 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 JavaDoc e) {
65             logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"+e);
66         }
67         try {
68             stmt = conn.createStatement();
69             stmt.execute("create table " + name +
70                          "(IDMAR integer not null primary key, NOM varchar(30))");
71             stmt.execute("insert into "+name+" values(0, 'Philippe Coq')");
72             stmt.execute("insert into "+name+" values(1, 'Philippe Durieux')");
73             stmt.execute("insert into "+name+" values(2, 'Adriana Danes')");
74             stmt.execute("insert into "+name+" values(3, 'Helene Joanin')");
75             stmt.close();
76             conn.close();
77         } catch(Exception JavaDoc e) {
78             logger.log(BasicLevel.ERROR, "Exception in createTable : \n"+e);
79             throw new RemoteException JavaDoc("Exception in createTable : "+e);
80         }
81         logger.log(BasicLevel.INFO, "Table "+name+" created");
82     }
83
84 }
85
86
87
Popular Tags