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, wait
batchUpdate, commit, isAutoCommit, operate, prepare, query, query, rollback, setAutoCommit, update
public 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 SQLDataType
tableName
- Name of the table to check fortrue
if the table existspublic boolean checkColumn(String tableName, String columnName)
checkColumn
in interface SQLDataType
tableName
- The table to look incolumnName
- The column to search fortrue
if the column existspublic void close()
close
in interface SQLDataType
close
in interface AutoCloseable
public boolean checkConnection()
public Connection getConnection()
Connection
object for ease of use in exposing more
internal APIgetConnection
in interface SQLDataType
Connection
object in use by this SQLDataType
public 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)
SQLDataType
true
setErrorOutput
in interface SQLDataType
errors
- false
to disable error outputpublic boolean isSendingErrorOutput()
SQLDataType
isSendingErrorOutput
in interface SQLDataType
true
if content is printed to the console.Copyright © 2015. All rights reserved.