public final class ConnectionsExtensions extends Object
ConnectionsExtensions have convenience methods to create and connect to mysql or postgresql
databases.| Modifier and Type | Field and Description |
|---|---|
static String |
MYSQL_DRIVERNAME
Constant for the drivername from MySQL-database.
|
static int |
MYSQL_PORT
Constant for the default port where the MySQL-database listen.
|
static String |
MYSQL_PREFIX_URL
Constant for the urlprefix from MySQL-database.
|
static String |
POSTGRESQL_DRIVERNAME
Constant for the drivername from PostgreSQL-database.
|
static int |
POSTGRESQL_PORT
Constant for the port where the PostgreSQL-database listen.
|
static String |
POSTGRESQL_PREFIX_URL
Constant for the urlprefix from PostgreSQL-database.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
dropPostgreSQLDatabase(String hostname,
String databaseName,
String dbuser,
String dbpasswort)
Drops the given PostgreSQL database with the given databaseName if it does exist.
|
static void |
executeSqlScript(BufferedReader bufferedReader,
Connection connection)
Execute the sql script in the given BufferedReader from a file.
|
static void |
executeSqlScript(BufferedReader bufferedReader,
Connection connection,
boolean log)
Execute the sql script in the given BufferedReader from a file.
|
static void |
executeSqlScript(Connection connection,
String sqlScript)
Execute the sql script given as String object.
|
static void |
executeSqlScript(Connection connection,
String sqlScript,
boolean log)
Execute the sql script given as String object.
|
static boolean |
existsMySqlDatabase(String hostname,
String databaseName,
String dbuser,
String dbpasswort)
Checks if the given database exists in the MySqlDatabase.
|
static boolean |
existsPostgreSQLDatabase(String hostname,
String databaseName,
String dbuser,
String dbpasswort)
Checks if the given database exists in the Postgresql Database.
|
static Connection |
getMySQLConnection(String hostname,
int portNumber,
String databaseName,
String dbuser,
String dbpasswort)
Gets the my sql connection.
|
static Connection |
getMySQLConnection(String hostname,
String databaseName,
String dbuser,
String dbpasswort)
Gets the my sql connection.
|
static Connection |
getPostgreSQLConnection(String hostname,
String databaseName,
String dbuser,
String dbpasswort)
Gets the postgre sql connection.
|
static Connection |
getPostgresSQLConnection(String hostname,
int portNumber,
String databaseName,
String dbuser,
String dbpasswort)
Gets the postgres sql connection from the given parameters.
|
static void |
newMySqlDatabase(String hostname,
String databaseName,
String dbuser,
String dbpasswort)
Creates a database with the given databaseName (and sets the characterset to utf8 and the
collate to utf8_general_ci) if it does not exist.
|
static void |
newMySqlDatabase(String hostname,
String databaseName,
String dbuser,
String dbpasswort,
String characterSet,
String collate)
Creates the a mySql database with the given databaseName if it does not exist.
|
static void |
newPostgreSQLDatabase(String hostname,
String databaseName,
String dbuser,
String dbpasswort,
String characterSet,
String collate)
Creates the a PostgreSQL database with the given databaseName if it does not exist.
|
public static final String MYSQL_DRIVERNAME
public static final String MYSQL_PREFIX_URL
public static final int MYSQL_PORT
public static final String POSTGRESQL_DRIVERNAME
public static final String POSTGRESQL_PREFIX_URL
public static final int POSTGRESQL_PORT
public static void dropPostgreSQLDatabase(String hostname, String databaseName, String dbuser, String dbpasswort) throws SQLException, ClassNotFoundException
hostname - the hostnamedatabaseName - the database namedbuser - the dbuserdbpasswort - the dbpasswortSQLException - is thrown if a database access error occurs or this method is called on a closed connectionClassNotFoundException - is thrown if the Class was not found or could not be locatedpublic static void executeSqlScript(BufferedReader bufferedReader, Connection connection) throws IOException, SQLException
bufferedReader - a BufferedReader from a script file.connection - the connectionIOException - Signals that an I/O exception has occurred.SQLException - is thrown if a database access error occurs or this method is called on a closed connectionpublic static void executeSqlScript(BufferedReader bufferedReader, Connection connection, boolean log) throws IOException, SQLException
bufferedReader - a BufferedReader from a script file.connection - the connectionlog - the flag if it will be logged.IOException - Signals that an I/O exception has occurred.SQLException - is thrown if a database access error occurs or this method is called on a closed connectionpublic static void executeSqlScript(Connection connection, String sqlScript) throws SQLException
sqlScript - The sql script as String object.connection - the connectionSQLException - is thrown if a database access error occurs or this method is called on a closed connectionpublic static void executeSqlScript(Connection connection, String sqlScript, boolean log) throws SQLException
sqlScript - The sql script as String object.connection - the connectionlog - the flag if it will be logged.SQLException - is thrown if a database access error occurs or this method is called on a closed connectionpublic static boolean existsMySqlDatabase(String hostname, String databaseName, String dbuser, String dbpasswort) throws SQLException, ClassNotFoundException
hostname - the hostnamedatabaseName - the database namedbuser - the dbuserdbpasswort - the dbpasswortSQLException - is thrown if a database access error occurs or this method is called on a closed connectionClassNotFoundException - is thrown if the Class was not found or could not be located.public static boolean existsPostgreSQLDatabase(String hostname, String databaseName, String dbuser, String dbpasswort) throws ClassNotFoundException, SQLException
hostname - the hostnamedatabaseName - the database namedbuser - the dbuserdbpasswort - the dbpasswortClassNotFoundException - is thrown if the Class was not found or could not be located.SQLException - is thrown if a database access error occurs or this method is called on a closed connectionpublic static Connection getMySQLConnection(String hostname, int portNumber, String databaseName, String dbuser, String dbpasswort) throws ClassNotFoundException, SQLException
hostname - the hostnameportNumber - the port numberdatabaseName - the database namedbuser - the dbuserdbpasswort - the dbpasswortClassNotFoundException - is thrown if the Class was not found or could not be located.SQLException - is thrown if a database access error occurs or this method is called on a closed connectionpublic static Connection getMySQLConnection(String hostname, String databaseName, String dbuser, String dbpasswort) throws ClassNotFoundException, SQLException
hostname - the hostnamedatabaseName - the database namedbuser - the dbuserdbpasswort - the dbpasswortClassNotFoundException - is thrown if the Class was not found or could not be located.SQLException - is thrown if a database access error occurs or this method is called on a closed connectionpublic static Connection getPostgreSQLConnection(String hostname, String databaseName, String dbuser, String dbpasswort) throws ClassNotFoundException, SQLException
hostname - the hostnamedatabaseName - the database namedbuser - the dbuserdbpasswort - the dbpasswortClassNotFoundException - is thrown if the Class was not found or could not be located.SQLException - is thrown if a database access error occurs or this method is called on a closed connectionpublic static Connection getPostgresSQLConnection(String hostname, int portNumber, String databaseName, String dbuser, String dbpasswort) throws ClassNotFoundException, SQLException
hostname - the hostnameportNumber - the port numberdatabaseName - the database namedbuser - the dbuserdbpasswort - the dbpasswortClassNotFoundException - is thrown if the Class was not found or could not be located.SQLException - is thrown if a database access error occurs or this method is called on a closed connectionpublic static void newMySqlDatabase(String hostname, String databaseName, String dbuser, String dbpasswort) throws SQLException, ClassNotFoundException
hostname - the hostnamedatabaseName - the database namedbuser - the dbuserdbpasswort - the dbpasswortSQLException - is thrown if a database access error occurs or this method is called on a closed connectionClassNotFoundException - is thrown if the Class was not found or could not be located.public static void newMySqlDatabase(String hostname, String databaseName, String dbuser, String dbpasswort, String characterSet, String collate) throws SQLException, ClassNotFoundException
hostname - the hostnamedatabaseName - the database namedbuser - the dbuserdbpasswort - the dbpasswortcharacterSet - the character setcollate - the collateSQLException - is thrown if a database access error occurs or this method is called on a closed connectionClassNotFoundException - is thrown if the Class was not found or could not be located.public static void newPostgreSQLDatabase(String hostname, String databaseName, String dbuser, String dbpasswort, String characterSet, String collate) throws SQLException, ClassNotFoundException
hostname - the hostnamedatabaseName - the database namedbuser - the dbuserdbpasswort - the dbpasswortcharacterSet - the character setcollate - the collateSQLException - is thrown if a database access error occurs or this method is called on a closed connectionClassNotFoundException - is thrown if the Class was not found or could not be located.Copyright © 2015–2017 Alpha Ro Group UG (haftungsbeschrÀngt). All rights reserved.