Java SQL Execute executeCreateDB(String className, String URL, String userName, String password, String dbName)

Here you can find the source of executeCreateDB(String className, String URL, String userName, String password, String dbName)

Description

execute Create DB

License

Apache License

Declaration

public static boolean executeCreateDB(String className, String URL, String userName, String password,
            String dbName) throws SQLException, ClassNotFoundException 

Method Source Code


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

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

import java.sql.SQLException;
import java.sql.Statement;

public class Main {
    public static boolean executeCreateDB(String className, String URL, String userName, String password,
            String dbName) throws SQLException, ClassNotFoundException {
        Connection con = null;//  w w  w.  j a v a2s  . com
        Statement stat = null;
        try {
            con = getConnection(className, URL, userName, password);
            stat = con.createStatement();
            int count = stat.executeUpdate("CREATE DATABASE IF NOT EXISTS " + dbName);

            return count > 0 ? true : false;
        } finally {
            if (stat != null) {
                stat.close();
            }
            if (con != null) {
                con.close();
            }
        }
    }

    public static Connection getConnection(String className, String URL, String userName, String password)
            throws ClassNotFoundException, SQLException {
        Class.forName(className);
        return DriverManager.getConnection(URL, userName, password);
    }
}

Related

  1. execute(List sql)
  2. execute(Statement statement, String sql)
  3. execute(String sql, Connection connection)
  4. executeCall(Connection connection, String command, String schemaName, String tableName, int paramLength)
  5. executeCallable(Connection conn, String sql)
  6. executeDDL(final Connection connection, final String sql, final int... ignoreErrors)
  7. executeDDL(String ddl)
  8. executeImmediate(String sql)
  9. executeInsert(Connection conn, String sql, boolean hasAutoGeneratedKey, Object... parameters)