KickJava   Java API By Example, From Geeks To Geeks.

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


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: Tfolder.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 Tfolder {
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("folderFileECB", "c_count integer, c_p1pk varchar(30), c_p2pk varchar(30)");
48     createTable("folderPaperECL", "c_value integer");
49     }
50
51     /**
52      * create a table
53      */

54     private static void createTable(String JavaDoc name, String JavaDoc fields) 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 + "(c_name varchar(30) not null primary key," + fields + ")");
74         stmt.close();
75         conn.close(); // release connection
76
} catch(Exception JavaDoc e) {
77         System.err.println("Exception in createTable : "+e);
78         throw new RemoteException JavaDoc("Exception in createTable : "+e);
79     }
80     }
81
82 }
83
84
Popular Tags