KickJava   Java API By Example, From Geeks To Geeks.

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


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: Tmessage.java,v 1.4 2003/06/03 14:51:45 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 Tmessage {
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("messageMRecordEC");
48     }
49
50     /**
51      * create a table
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     } catch(Exception JavaDoc e) {
69     }
70     try {
71         stmt = conn.createStatement();
72         stmt.execute("create table " + name +
73              "(c_uuid varchar(20) not null, c_dest varchar(30), c_value integer, c_mdb varchar(30) not null,"+
74              "primary key (c_uuid, c_mdb))");
75         stmt.close();
76         conn.close(); // release connection
77
} catch(Exception JavaDoc e) {
78         System.err.println("Exception in createTable : "+e);
79         throw new RemoteException JavaDoc("Exception in createTable : "+e);
80     }
81     }
82
83 }
84
85
Popular Tags