Java JDBC MySQL Connection getConnection()

Here you can find the source of getConnection()

Description

Returns a database connection.

License

Open Source License

Declaration

public static Connection getConnection() 

Method Source Code


//package com.java2s;
/*         This file is part of the USIP Open Simulation Platform.<br>
* 
*         The USIP Open Simulation Platform is free software; you can
*         redistribute it and/or modify it under the terms of the new BSD Style
*         license associated with this distribution.<br>
* 
*         The USIP Open Simulation Platform is distributed WITHOUT ANY
*         WARRANTY; without even the implied warranty of MERCHANTABILITY or
*         FITNESS FOR A PARTICULAR PURPOSE. <BR>
* 
*///w w  w  .  j a  v a  2s  . c o  m

import java.sql.*;

public class Main {
    private static String conn_string;

    /**
     * Returns a database connection.
     * 
     * @return
     */
    public static Connection getConnection() {
        Connection connection = null;

        try {
            Class.forName("org.gjt.mm.mysql.Driver").newInstance(); //$NON-NLS-1$

            connection = DriverManager.getConnection(conn_string);

            return connection;

        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }
}

Related

  1. getConnection()
  2. getConnection()
  3. getConnection()
  4. getConnection()
  5. getConnection()
  6. getConnection()
  7. getConnection()
  8. getConnection()
  9. getConnection()