Java JDBC MySQL Connection getConnection()

Here you can find the source of getConnection()

Description

get Connection

License

Apache License

Declaration

public static Connection getConnection() 

Method Source Code


//package com.java2s;
//License from project: Apache License 

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

public class Main {
    static final String DB_URL = "jdbc:mysql://localhost/pos";
    static final String USER = "root";
    static final String PASS = "";
    static Connection connection = null;

    public static Connection getConnection() {
        try {// w ww  . j  a  va  2  s .  c  om
            Class.forName("com.mysql.jdbc.Driver");
            //STEP 3: Open a connection
            System.out.println("Connecting to database...");
            connection = (Connection) DriverManager.getConnection(DB_URL, USER, PASS);
        } catch (Exception e) {
            System.out.println("Class path not found");
        }
        return connection;

    }
}

Related

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