KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mysql > jdbc > MiniAdmin


1 /*
2    Copyright (C) 2002 MySQL AB
3
4       This program is free software; you can redistribute it and/or modify
5       it under the terms of the GNU General Public License as published by
6       the Free Software Foundation; either version 2 of the License, or
7       (at your option) any later version.
8
9       This program is distributed in the hope that it will be useful,
10       but WITHOUT ANY WARRANTY; without even the implied warranty of
11       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12       GNU General Public License for more details.
13
14       You should have received a copy of the GNU General Public License
15       along with this program; if not, write to the Free Software
16       Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18  */

19 package com.mysql.jdbc;
20
21 import java.sql.SQLException JavaDoc;
22
23 import java.util.Properties JavaDoc;
24
25
26 /**
27  * Utility functions for admin functionality from Java.
28  *
29  * @author Mark Matthews
30  */

31 public class MiniAdmin {
32     private Connection conn;
33
34     /**
35      * Create a new MiniAdmin using the given connection
36      *
37      * @param conn the existing connection to use.
38      *
39      * @throws SQLException if an error occurs
40      */

41     public MiniAdmin(java.sql.Connection JavaDoc conn) throws SQLException JavaDoc {
42         if (conn == null) {
43             throw new SQLException JavaDoc("Conection can not be null.", SQLError.SQL_STATE_GENERAL_ERROR);
44         }
45
46         if (!(conn instanceof Connection)) {
47             throw new SQLException JavaDoc("MiniAdmin can only be used with MySQL connections",
48                 SQLError.SQL_STATE_GENERAL_ERROR);
49         }
50
51         this.conn = (Connection) conn;
52     }
53
54     /**
55      * Create a new MiniAdmin, connecting using the given JDBC
56      * URL.
57      *
58      * @param jdbcUrl the JDBC URL to use
59      *
60      * @throws SQLException if an error occurs
61      */

62     public MiniAdmin(String JavaDoc jdbcUrl) throws SQLException JavaDoc {
63         this(jdbcUrl, new Properties JavaDoc());
64     }
65
66     /**
67      * Create a new MiniAdmin, connecting using the given JDBC
68      * URL and properties
69      *
70      * @param jdbcUrl the JDBC URL to use
71      * @param props the properties to use when connecting
72      *
73      * @throws SQLException if an error occurs
74      */

75     public MiniAdmin(String JavaDoc jdbcUrl, Properties JavaDoc props)
76         throws SQLException JavaDoc {
77         this.conn = (Connection) (new Driver().connect(jdbcUrl, props));
78     }
79
80     /**
81      * Shuts down the MySQL server at the other end of the connection
82      * that this MiniAdmin was created from/for.
83      *
84      * @throws SQLException if an error occurs
85      */

86     public void shutdown() throws SQLException JavaDoc {
87         conn.shutdownServer();
88     }
89 }
90
Popular Tags