KickJava   Java API By Example, From Geeks To Geeks.

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


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: Tpfloat.java,v 1.7 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 'pfloat' bean of 'etype'.
38  * @author Helene Joanin
39  */

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

45     public static void init() throws NamingException JavaDoc, RemoteException JavaDoc {
46     mgrInit();
47     createTable("JT_EtypePfloatEC");
48     }
49
50     /**
51      * create a table for the pfloat 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 = "real"; // 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.0)");
78         stmt.execute("insert into "+name+" values('pk2', 2.0)");
79         stmt.execute("insert into "+name+" values('pk3', 3.0)");
80         stmt.execute("insert into "+name+" values('pk4', 4.0)");
81         stmt.execute("insert into "+name+" values('pk5', 5.0)");
82         stmt.execute("insert into "+name+" values('pk5bis', 5.0)");
83         stmt.execute("insert into "+name+" values('pktoremove', 10000.0)");
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