Java JDBC MySQL Connection getConnection()

Here you can find the source of getConnection()

Description

get Connection

License

Open Source License

Declaration

public static Connection getConnection() throws Exception 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.sql.Connection;
import java.sql.DriverManager;

public class Main {
    private static ThreadLocal<Connection> conns = new ThreadLocal<Connection>();

    public static Connection getConnection() throws Exception {
        Connection conn = conns.get();
        if (conn == null) {
            Class.forName("com.mysql.jdbc.Driver");
            String url = "jdbc:mysql://localhost:3306/insurancemall";
            conn = DriverManager.getConnection(url, "root", "");
            conns.set(conn);/*from   w ww  . ja va 2 s.co m*/
        }
        return conn;
    }
}

Related

  1. getConnection()
  2. getConnection()
  3. getConnection()
  4. getConnection()
  5. getConnection()
  6. getConnection()
  7. getConnection()
  8. getConnection(final String host, final int port, final String schema, final String user, final String password)
  9. getConnection(String connectionType)