KickJava   Java API By Example, From Geeks To Geeks.

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


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: Ttransacted.java,v 1.7 2003/09/17 08:56:40 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 import javax.naming.NamingException JavaDoc;
32 import javax.sql.DataSource JavaDoc;
33
34 public class Ttransacted {
35
36     static DataSource JavaDoc dataSource = null;
37
38     /**
39      * Entry point
40      */

41     public static void init() throws NamingException JavaDoc, RemoteException JavaDoc {
42       
43         // Get DataSource
44
dataSource = DBEnvSL.getDataSource("jdbc_1");
45     
46         // create tables
47
createTable("transactedSimpleEB");
48         createTable("transactedSimpleEC");
49     }
50
51     /**
52      * create a table
53      */

54     private static void createTable(String JavaDoc name) throws RemoteException JavaDoc {
55
56         // get connection
57
Connection JavaDoc conn = null;
58         try {
59             conn = dataSource.getConnection();
60         } catch(Exception JavaDoc e) {
61             throw new RemoteException JavaDoc("Cannot get Connection");
62         }
63     
64         Statement JavaDoc stmt;
65         try {
66             stmt = conn.createStatement();
67             stmt.execute("DROP TABLE "+name);
68             stmt.close();
69         } catch(Exception JavaDoc e) {
70         }
71         try {
72             stmt = conn.createStatement();
73             stmt.execute("create table " + name +
74                          "(c_accno varchar(12) not null primary key,"+
75                          "c_customer varchar(20), c_balance integer, c_ident integer, c_count integer )");
76             stmt.execute("insert into "+name+" values('pk1', 'NotSupported', 4, 0, 0)");
77             stmt.execute("insert into "+name+" values('pk2', 'Required', 8, 0, 0)");
78             stmt.execute("insert into "+name+" values('pk3', 'Never', 16, 0, 0)");
79             stmt.execute("insert into "+name+" values('pk4', 'RequiresNew', 32, 0, 0)");
80             stmt.execute("insert into "+name+" values('pk5', 'Mandatory', 64, 0, 0)");
81             stmt.execute("insert into "+name+" values('pk6', 'Supports', 128, 0, 0)");
82             stmt.close();
83             conn.close(); // release connection
84
} catch(Exception JavaDoc e) {
85             System.err.println("Exception in createTable : "+e);
86             throw new RemoteException JavaDoc("Exception in createTable : "+e);
87         }
88     }
89
90 }
91
92
93
Popular Tags