Example usage for java.sql DriverManager getConnection

List of usage examples for java.sql DriverManager getConnection

Introduction

In this page you can find the example usage for java.sql DriverManager getConnection.

Prototype

@CallerSensitive
public static Connection getConnection(String url, java.util.Properties info) throws SQLException 

Source Link

Document

Attempts to establish a connection to the given database URL.

Usage

From source file:com.sludev.mssqlapplylog.MSSQLHelper.java

/**
 * Get a Connection for use with the current SQL Server Host.
 * @param sqlURL A SQL Server connection string
 * @param props Properties that should include the SQL Server username and password
 * @return A valid connection object or null on failure
 */// ww w.ja  va  2s  .  c  o  m
public static Connection getConn(String sqlURL, Properties props) {
    Connection conn = null;
    try {
        conn = DriverManager.getConnection(sqlURL, props);
    } catch (SQLException ex) {
        LOGGER.debug(String.format("Error getting connection. '%s'", sqlURL), ex);

        return null;
    }

    try {
        conn.setAutoCommit(true);
    } catch (SQLException ex) {
        LOGGER.error("Error setting autocommit() on connection.", ex);

        return null;
    }

    return conn;
}