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 |
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 |
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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
commit, isAutoCommit, prepare, 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) throws SQLException
checkTable
in interface SQLDataType
tablename
- Name of the table to check forSQLException
- The query on the database failspublic 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 openCopyright © 2015. All rights reserved.