public class MySQL extends Object implements SQLDataType
| Modifier and Type | Class and Description |
|---|---|
static class |
MySQL.ConnectionPrefs
Subclass for managing connection preferences.
|
| Constructor and Description |
|---|
MySQL(MySQL.ConnectionPrefs pref)
Creates a new
MySQL object for use in working with a database |
MySQL(String host,
String user,
String pass,
String database,
String port)
Creates a new
MySQL object for use in working with a database |
| Modifier and Type | Method and Description |
|---|---|
boolean |
checkColumn(String tableName,
String columnName)
Checks if a table has the following column
|
boolean |
checkConnection()
Checks to make sure the connection is active to the MySQL server
|
boolean |
checkTable(String tableName)
Checks if a table exists within the set database
|
void |
close() |
Connection |
getConnection()
Returns the
Connection object for ease of use in exposing more
internal API |
boolean |
isSendingErrorOutput()
Determines whether or not to automatically print errors to the console
|
static Cache<MySQL> |
newCache(MySQL.ConnectionPrefs prefs,
long keepAliveMS)
Returns a new cached MySQL connection, which will automatically renew
itself at the specified interval via
keepAliveMS, in
milliseconds. |
Connection |
open()
Opens a connection to the SQL database.
|
void |
setErrorOutput(boolean errors)
Sets whether or not to print errors to the console automatically.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitbatchUpdate, commit, isAutoCommit, operate, prepare, query, query, rollback, setAutoCommit, updatepublic MySQL(String host, String user, String pass, String database, String port)
MySQL object for use in working with a databasehost - The hostname to useuser - The username to usepass - The password to usedatabase - The database to useport - The port number to usepublic MySQL(MySQL.ConnectionPrefs pref)
MySQL object for use in working with a databasepref - A MySQL.ConnectionPrefs for this MySQL objectpublic Connection open() throws SQLException
SQLDataType.close() or wrap in try-with-resources after you are
finished working with the database for your segment of your code.SQLException - If the connection fails to openpublic boolean checkTable(String tableName)
checkTable in interface SQLDataTypetableName - Name of the table to check fortrue if the table existspublic boolean checkColumn(String tableName, String columnName)
checkColumn in interface SQLDataTypetableName - The table to look incolumnName - The column to search fortrue if the column existspublic void close()
close in interface SQLDataTypeclose in interface AutoCloseablepublic boolean checkConnection()
public Connection getConnection()
Connection object for ease of use in exposing more
internal APIgetConnection in interface SQLDataTypeConnection object in use by this SQLDataTypepublic static Cache<MySQL> newCache(MySQL.ConnectionPrefs prefs, long keepAliveMS)
keepAliveMS, in
milliseconds. Keep in mind, due to the way Cache works,
until Cache.get() is called a connection may remain open past
the specified keep-aliveprefs - The MySQL.ConnectionPrefs relevant to the connectionkeepAliveMS - The time in milliseconds to keep a connection openCache object with an instance of thispublic void setErrorOutput(boolean errors)
SQLDataTypetruesetErrorOutput in interface SQLDataTypeerrors - false to disable error outputpublic boolean isSendingErrorOutput()
SQLDataTypeisSendingErrorOutput in interface SQLDataTypetrue if content is printed to the console.Copyright © 2017. All rights reserved.