KickJava   Java API By Example, From Geeks To Geeks.

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


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: Tointeger.java,v 1.1 2003/09/05 13:03:29 joaninh 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 import javax.naming.NamingException JavaDoc;
32 import org.objectweb.util.monolog.api.BasicLevel;
33
34 /**
35  * Class to create tables for the 'ointeger' bean of 'etype'.
36  * @author Helene Joanin
37  */

38 public class Tointeger extends Tmanager {
39
40     /**
41      * Entry point
42      */

43     public static void init() throws NamingException JavaDoc, RemoteException JavaDoc {
44         mgrInit();
45         createTable("JT_EtypeOintegerEC");
46     }
47
48     /**
49      * create a table for the plong bean of etype
50      */

51     private static void createTable(String JavaDoc name) throws RemoteException JavaDoc {
52
53         // get connection
54
Connection JavaDoc conn = null;
55         try {
56             conn = dataSource.getConnection();
57         } catch (Exception JavaDoc e) {
58             throw new RemoteException JavaDoc("Cannot get Connection");
59         }
60
61         Statement JavaDoc stmt;
62         try {
63             stmt = conn.createStatement();
64             stmt.execute("DROP TABLE " + name);
65             stmt.close();
66             logger.log(BasicLevel.INFO, "Table " + name + " dropped");
67         } catch (Exception JavaDoc e) {
68             logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n" + e);
69         }
70         try {
71             String JavaDoc cTypeName = "integer"; // standard jdbc type name
72
stmt = conn.createStatement();
73             stmt.execute("create table " + name
74                          + "( c_pk varchar(30) not null primary key, c_f1 " + cTypeName + ")");
75             stmt.execute("insert into " + name + " values('pk1', 1)");
76             stmt.execute("insert into " + name + " values('pk2', 2)");
77             stmt.execute("insert into " + name + " values('pk3', 3)");
78             stmt.execute("insert into " + name + " values('pk4', 4)");
79             stmt.execute("insert into " + name + " values('pk5', 5)");
80             stmt.execute("insert into " + name + " values('pk5bis', 5)");
81             stmt.execute("insert into " + name + " values('pktoremove', 10000)");
82             stmt.execute("insert into " + name + " values('pknull', NULL)");
83             stmt.execute("insert into " + name + " values('pkchangenull', 10000)");
84
85             stmt.close();
86             conn.close(); // release connection
87
} catch (Exception JavaDoc e) {
88             logger.log(BasicLevel.ERROR, "Exception in createTable : " + e);
89             throw new RemoteException JavaDoc("Exception in createTable : " + e);
90         }
91         logger.log(BasicLevel.INFO, "Table " + name + " created");
92     }
93
94 }
95
Popular Tags