KickJava   Java API By Example, From Geeks To Geeks.

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


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: Toshort.java,v 1.6 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 /**
37  * Class to create tables for the 'oshort' bean of 'etype'.
38  * @author Helene Joanin
39  */

40 public class Toshort extends Tmanager {
41
42     /**
43      * Entry point
44      */

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

53     private static void createTable(String JavaDoc name) throws RemoteException JavaDoc {
54
55     // get connection
56
Connection JavaDoc conn = null;
57     try {
58         conn = dataSource.getConnection();
59     } catch(Exception JavaDoc e) {
60         throw new RemoteException JavaDoc("Cannot get Connection");
61     }
62     
63     Statement JavaDoc stmt;
64     try {
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         String JavaDoc cTypeName = "smallint"; // standard jdbc type name
74
stmt = conn.createStatement();
75         stmt.execute("create table " + name +
76              "( c_pk varchar(30) not null primary key, c_f1 "+cTypeName+")");
77         stmt.execute("insert into "+name+" values('pk1', 1)");
78         stmt.execute("insert into "+name+" values('pk2', 2)");
79         stmt.execute("insert into "+name+" values('pk3', 3)");
80         stmt.execute("insert into "+name+" values('pk4', 4)");
81         stmt.execute("insert into "+name+" values('pk5', 5)");
82         stmt.execute("insert into "+name+" values('pk5bis', 5)");
83         stmt.execute("insert into "+name+" values('pktoremove', 10000)");
84         stmt.execute("insert into "+name+" values('pknull', NULL)");
85         stmt.execute("insert into "+name+" values('pkchangenull', 10000)");
86
87         stmt.close();
88         conn.close(); // release connection
89
} catch(Exception JavaDoc e) {
90         logger.log(BasicLevel.ERROR, "Exception in createTable : "+e);
91         throw new RemoteException JavaDoc("Exception in createTable : "+e);
92     }
93     logger.log(BasicLevel.INFO, "Table "+name+" created");
94     }
95
96 }
97
Popular Tags