KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nilostep > xlsql > jdbc > xlConnectionMySQL


1 /*(Header: NiLOSTEP / xlSQL)
2
3     Copyright (C) 2004 NiLOSTEP Information Sciences, all
4     rights reserved.
5     
6     This program is licensed under the terms of the GNU
7     General Public License.You should have received a copy
8     of the GNU General Public License along with this
9     program;
10 */

11
12 /*
13  * xlConnectionHSQL.java
14  *
15  * Created on 5 juli 2004, 23:59
16  */

17 package com.nilostep.xlsql.jdbc;
18
19 import com.nilostep.xlsql.sql.*;
20
21 import java.sql.*;
22 import java.util.*;
23
24 /**
25  * DOCUMENT ME!
26  *
27  * @author Jim Caprioli
28  */

29 public class xlConnectionMySQL extends xlConnection {
30     //~ Instance variables ·····················································
31

32     private String JavaDoc context;
33
34     //~ Constructors ···························································
35

36     /**
37      * Creates a new instance of type xlConnectionMySQL.
38      *
39      * @param url
40      * @param info
41      *
42      * @throws SQLException
43      */

44     public xlConnectionMySQL(String JavaDoc url,
45                              Properties info) throws SQLException {
46         try {
47             String JavaDoc sql_url;
48             String JavaDoc sql_database;
49             String JavaDoc sql_user;
50             String JavaDoc sql_password;
51
52             if (info.getProperty("sql.url") != null) {
53                 sql_url = info.getProperty("sql.url");
54             } else {
55                 throw new SQLException("xlSQL: MySQL url empty");
56             }
57
58             if (info.getProperty("sql.database") != null) {
59                 sql_database = info.getProperty("sql.database");
60             } else {
61                 throw new SQLException("xlSQL: MySQL database empty");
62             }
63
64             if (info.getProperty("sql.user") != null) {
65                 sql_user = info.getProperty("sql.user");
66             } else {
67                 sql_user = "";
68             }
69
70             if (info.getProperty("sql.password") != null) {
71                 sql_password = info.getProperty("sql.password");
72             } else {
73                 sql_password = "";
74             }
75
76             context = sql_database;
77             URL = url;
78             w = xlSqlWriterFactory.create("mysql");
79
80
81             //NiLOSTEP...
82
// ... Stack Overflow 'BUG' occurs here
83
//End
84
dbCon = DriverManager.getConnection(sql_url, sql_user, sql_password);
85             query = xlSqlSelectFactory.create("mysql", dbCon);
86             startup();
87             xlsql = xlSqlFactory.create("mysql", datastore, context);
88             
89         } catch (Exception JavaDoc e) {
90             throw new SQLException("xlSQL: connect to MySQL " +
91                                    e.getMessage());
92         }
93     }
94
95     //~ Methods ································································
96

97     /**
98      * TODO: javadoc
99      *
100      * @throws Throwable
101      */

102     protected void finalize() throws Throwable JavaDoc {
103         shutdown();
104     }
105
106     /**
107      * TODO: javadoc
108      *
109      * @throws Exception
110      */

111     public void shutdown() throws Exception JavaDoc {
112         if (!closed) {
113             logger.info("Executing MySQL clean-up...");
114             String JavaDoc[] schemas = datastore.getSchemas();
115             Statement stm = dbCon.createStatement();
116             stm.execute("USE " + context);
117
118             for (int i = 0; i < schemas.length; i++) {
119                 stm.execute("DROP DATABASE " + schemas[i]);
120             }
121             dbCon.close();
122             closed = true;
123             logger.info("MySQL clean-up done");
124         }
125     }
126 }
Popular Tags