Here you can find the source of canConnect(Properties dbSettings)
Parameter | Description |
---|---|
dbSettings | The datatabase connection settings |
Parameter | Description |
---|---|
SQLException | an exception |
true
if is possible to connect to the database server and false
otherwise.
public static void canConnect(Properties dbSettings) throws SQLException
//package com.java2s; /******************************************************************************* * Copyright (c) {2009,2011} {Software Design and Collaboration Laboratory (SDCL) * , University of California, Irvine}. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors://from w w w. j a va 2 s. c om * {Software Design and Collaboration Laboratory (SDCL) * , University of California, Irvine} * - initial API and implementation and/or initial documentation *******************************************************************************/ import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.util.Properties; public class Main { /** * Returns whether is possible to connect to the database server for a given * connection settings. * * @param dbSettings * The datatabase connection settings * @return <code>true</code> if is possible to connect to the database * server and <code>false</code> otherwise. * @throws SQLException */ public static void canConnect(Properties dbSettings) throws SQLException { String url = dbSettings.getProperty("hibernate.connection.url"); String username = dbSettings.getProperty("hibernate.connection.username"); String password = dbSettings.getProperty("hibernate.connection.password"); Connection conn = DriverManager.getConnection(url, username, password); conn.close(); } }