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() 

Method Source Code


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

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

public class Main {
    private static Connection con;

    public static Connection getConnection() {
        if (con == null) {

            try {
                //System.out.println("1");
                Class.forName("com.mysql.jdbc.Driver");
                con = DriverManager
                        .getConnection("jdbc:mysql://localhost:3306/facturacion?user=root&password=1111");
                //con = DriverManager.getConnection("jdbc:mysql://192.168.200.18:3306/facturacion?user=root&password=1111");

                //System.out.println("2");
                con.setAutoCommit(false);
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();//w  w w  . j  a v a  2s . c o  m
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
        return con;
    }
}

Related

  1. createConnectionUtf8(String connString)
  2. createTable(String dbFile, String tableName, String tableDefinition)
  3. deleteTableData(String tableName)
  4. getAllNames()
  5. getConnection()
  6. getConnection()
  7. getConnection()
  8. getConnection()
  9. getConnection()