public class MysqlDatabase extends AbstractGenericDatabase implements IDatabase
Constructor and Description |
---|
MysqlDatabase(java.lang.String host,
java.lang.String username,
java.lang.String password,
java.lang.String database)
Used to create a MYSQL database controller class.
|
Modifier and Type | Method and Description |
---|---|
java.sql.Connection |
createConnection()
This is used to get a connection to the database
|
boolean |
dropTable(java.sql.Connection connection,
java.lang.String tableName)
This is called to delete a table from the database
|
void |
executeSQL(java.sql.Connection connection,
java.lang.String sql)
This is used to execute a simple SQL statement on the database.
|
java.lang.String |
getConnectionUrl()
Used to get the connection url used to connect to the database
|
java.sql.PreparedStatement |
getStatement(java.sql.Connection connection,
java.lang.String sql)
This is used to create a PreparedStatement from the give SQL.
|
void |
init()
This is used to setup the database manager class, it should be called after creating a
database manager class.
|
void |
setHost(java.lang.String host)
Used to set the host name of the database server
|
void |
setPassword(java.lang.String password)
Used to set the password used to connect to the database
|
void |
setUsername(java.lang.String username)
Used to set the username used to connect to the database
|
closeConnection, closeDatabaseResources, commitTransactionConnection, createTransactionConnection, dropTable, executeSQL, executeUpdate, executeUpdate, getStatement, insertIntoTable, insertIntoTable, rollbackTransactionConnection
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
closeConnection, closeDatabaseResources, commitTransactionConnection, createTransactionConnection, dropTable, executeSQL, executeUpdate, executeUpdate, getStatement, insertIntoTable, insertIntoTable, rollbackTransactionConnection
public MysqlDatabase(java.lang.String host, java.lang.String username, java.lang.String password, java.lang.String database)
host
- The database hostusername
- The name of the user used to access the databasepassword
- The name of the password used to access the databasedatabase
- The name of the database to connect topublic void init() throws UnableToConnectToDatabaseException
init
in interface IDatabase
UnableToConnectToDatabaseException
public java.lang.String getConnectionUrl()
public java.sql.Connection createConnection() throws java.sql.SQLException
createConnection
in interface IDatabase
java.sql.SQLException
- Thrown if their is a problem getting the connection to the databasepublic void setHost(java.lang.String host)
host
- The host name of the database serverpublic void setUsername(java.lang.String username)
username
- The username used to connect to the databasepublic void setPassword(java.lang.String password)
password
- The password used to connect to the databasepublic boolean dropTable(java.sql.Connection connection, java.lang.String tableName)
public java.sql.PreparedStatement getStatement(java.sql.Connection connection, java.lang.String sql) throws java.sql.SQLException
getStatement
in interface IDatabase
connection
- A connection to the databasesql
- The statements sqljava.sql.SQLException
- Thrown if their is a problem creating the statementPreparedStatement
public void executeSQL(java.sql.Connection connection, java.lang.String sql) throws java.sql.SQLException
executeSQL
in interface IDatabase
connection
- a connection to be re-used, useful for running a series
of updates as a transactionsql
- the SQL to execute on the databasejava.sql.SQLException
- Thrown if their is a problem talking to the database