Java JDBC MySQL Connection createConnection()

Here you can find the source of createConnection()

Description

create Connection

License

Open Source License

Declaration

public static Connection createConnection() 

Method Source Code


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

import java.sql.*;

public class Main {
    private static Connection connection;
    private static final String ConnectionString = "jdbc:mysql://localhost:3306/tune_bazaar";
    private static final String user = "miserman";
    private static final String pwd = "NgxTy88";

    public static Connection createConnection() {

        System.out.println("Creating database connection...");

        String driverName = "com.mysql.jdbc.Driver";
        try {/*www.  j  av  a 2s  . com*/
            Class.forName(driverName);
        } catch (ClassNotFoundException ex) {
            System.out.println(ex.getMessage());
        }

        try {
            connection = DriverManager.getConnection(ConnectionString, user, pwd);
        } catch (SQLException ex) {
            System.out.println("Error - Creating database connection...");
            System.out.println(ex.getMessage());
        }

        return connection;

    }
}

Related

  1. addItem(int itemId, String itemName, int page, String tradeable)
  2. checkConnection(String dbFile)
  3. computeAverageGeneIdsPerName()
  4. createConnection(String hostname, String port, String database, String username, String password)
  5. createConnection(String url, String user, String password)
  6. createConnectionUtf8(String connString)
  7. createTable(String dbFile, String tableName, String tableDefinition)