KickJava   Java API By Example, From Geeks To Geeks.

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


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: Tjdbcra.java,v 1.1 2003/10/28 00:43:30 tonyortiz 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 Tjdbcra {
35
36     static DataSource JavaDoc dataSource = null;
37
38     /**
39      * Entry point
40      */

41
42     public static void init() throws NamingException JavaDoc, RemoteException JavaDoc {
43       
44     // Get DataSource
45
dataSource = DBEnvSL.getDataSource("jdbc_xa1");
46     
47     // create first table
48
createTable("JDBC_XA1");
49
50         dataSource = null;
51
52         // create second table
53
dataSource = DBEnvSL.getDataSource("jdbc_xa2");
54         createTable("JDBC_XA2");
55
56         dataSource = null;
57     }
58
59     /**
60      * create a table
61      */

62     private static void createTable(String JavaDoc name) throws RemoteException JavaDoc {
63
64     // get connection
65

66     Connection JavaDoc conn = null;
67
68     try {
69         conn = dataSource.getConnection();
70     } catch(Exception JavaDoc e) {
71         throw new RemoteException JavaDoc("Cannot get Connection");
72     }
73     
74     Statement JavaDoc stmt;
75
76     try {
77         stmt = conn.createStatement();
78         stmt.execute("DROP TABLE "+name);
79         stmt.close();
80     } catch(Exception JavaDoc e) {
81         System.err.println("Exception in dropTable : \n"+e);
82     }
83
84     try {
85         stmt = conn.createStatement();
86         stmt.execute("create table " + name +
87              "(xa_accno integer not null primary key,"+
88              "xa_customer varchar(20), xa_balance float )");
89         stmt.close();
90             conn.close();
91     } catch(Exception JavaDoc e) {
92         System.err.println("Exception in createTable : \n"+e);
93         throw new RemoteException JavaDoc("Exception in createTable : "+e);
94     }
95     }
96 }
97
98
99
Popular Tags