01: /*
02: * JOnAS: Java(TM) Open Application Server
03: * Copyright (C) 1999 Bull S.A.
04: * Contact: jonas-team@objectweb.org
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * 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:
23: * --------------------------------------------------------------------------
24: */
25:
26: package org.objectweb.jonas.jtests.ftables;
27:
28: import java.rmi.RemoteException;
29: import java.sql.Connection;
30: import java.sql.Statement;
31: import javax.naming.NamingException;
32: import javax.sql.DataSource;
33:
34: public class Tffolder {
35:
36: static DataSource dataSource = null;
37:
38: /**
39: * Entry point
40: */
41: public static void init() throws NamingException, RemoteException {
42:
43: // Get DataSource
44: dataSource = DBEnvSL.getDataSource("jdbc_1");
45:
46: // create tables
47: createTable("ffolderFileECB",
48: "c_count integer, c_p1pk varchar(30), c_p2pk varchar(30)");
49: createTable("ffolderPaperECL", "c_value integer");
50: }
51:
52: /**
53: * create a table
54: */
55: private static void createTable(String name, String fields)
56: throws RemoteException {
57:
58: // get connection
59: Connection conn = null;
60: try {
61: conn = dataSource.getConnection();
62: } catch (Exception e) {
63: throw new RemoteException("Cannot get Connection");
64: }
65:
66: Statement stmt;
67: try {
68: stmt = conn.createStatement();
69: stmt.execute("DROP TABLE " + name);
70: stmt.close();
71: } catch (Exception e) {
72: }
73: try {
74: stmt = conn.createStatement();
75: stmt.execute("create table " + name
76: + "(c_name varchar(30) not null primary key,"
77: + fields + ")");
78: stmt.close();
79: conn.close(); // release connection
80: } catch (Exception e) {
81: System.err.println("Exception in createTable : " + e);
82: throw new RemoteException("Exception in createTable : " + e);
83: }
84: }
85:
86: }
|