MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JdbcDriverTest.java
1 /* -*- mode: java; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=4:tabstop=4:smarttab:
3  *
4  * Copyright 2010 Sun Microsystems, Inc.
5  * All rights reserved. Use is subject to license terms.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; version 2 of the License.
10  *
11  * This program 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
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 package com.mysql.cluster.crund;
22 
23 import java.sql.*;
24 
28 public class JdbcDriverTest {
29  static public void main(String[] args) throws Exception {
30  System.out.println("main()");
31 
32  System.out.println();
33  System.out.println("properties:");
34  final String driver = System.getProperty("jdbc.driver");
35  final String url = System.getProperty("jdbc.url");
36  final String user = System.getProperty("jdbc.user");
37  final String password = System.getProperty("jdbc.password");
38  System.out.println("jdbc.driver: " + driver);
39  System.out.println("jdbc.url: " + url);
40  System.out.println("jdbc.user: " + user);
41  System.out.println("jdbc.password: " + password);
42 
43  System.out.println();
44  System.out.println("load jdbc driver ...");
45  if (driver == null) {
46  throw new RuntimeException("Missing property: jdbc.driver");
47  }
48  try {
49  //Class.forName(driver);
50  Class.forName(driver).newInstance();
51  } catch (ClassNotFoundException e) {
52  System.out.println("Cannot load JDBC driver '" + driver
53  + "' from classpath '"
54  + System.getProperty("java.class.path") + "'");
55  throw e;
56  }
57 
58  System.out.println();
59  System.out.println("testing connection ...");
60  if (url == null) {
61  throw new RuntimeException("Missing property: jdbc.url");
62  }
63  try {
64  Connection conn = DriverManager.getConnection(url, user, password);
65  System.out.println("conn = " + conn);
66  conn.close();
67  } catch (SQLException e) {
68  System.out.println("Cannot connect to database, exception: "
69  + e.getMessage());
70  throw e;
71  }
72 
73  System.out.println();
74  System.out.println("main(): done.");
75  }
76 }