org.stanwood.media.database
Class MysqlDatabase

java.lang.Object
  extended by org.stanwood.media.database.AbstractGenericDatabase
      extended by org.stanwood.media.database.MysqlDatabase
All Implemented Interfaces:
IDatabase

public class MysqlDatabase
extends AbstractGenericDatabase
implements IDatabase

This is a database manager class were the database is connected directly via TCP/IP to a MySQL database.


Constructor Summary
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.
 
Method Summary
 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
 
Methods inherited from class org.stanwood.media.database.AbstractGenericDatabase
closeConnection, closeDatabaseResources, commitTransactionConnection, createTransactionConnection, dropTable, executeSQL, executeUpdate, executeUpdate, getStatement, insertIntoTable, insertIntoTable, rollbackTransactionConnection
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.stanwood.media.database.IDatabase
closeConnection, closeDatabaseResources, commitTransactionConnection, createTransactionConnection, dropTable, executeSQL, executeUpdate, executeUpdate, getStatement, insertIntoTable, insertIntoTable, rollbackTransactionConnection
 

Constructor Detail

MysqlDatabase

public 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.

Parameters:
host - The database host
username - The name of the user used to access the database
password - The name of the password used to access the database
database - The name of the database to connect to
Method Detail

init

public void init()
          throws UnableToConnectToDatabaseException
This is used to setup the database manager class, it should be called after creating a database manager class.

Specified by:
init in interface IDatabase
Throws:
UnableToConnectToDatabaseException

getConnectionUrl

public java.lang.String getConnectionUrl()
Used to get the connection url used to connect to the database

Returns:
The connection url

createConnection

public java.sql.Connection createConnection()
                                     throws java.sql.SQLException
This is used to get a connection to the database

Specified by:
createConnection in interface IDatabase
Returns:
The connection to the database
Throws:
java.sql.SQLException - Thrown if their is a problem getting the connection to the database

setHost

public void setHost(java.lang.String host)
Used to set the host name of the database server

Parameters:
host - The host name of the database server

setUsername

public void setUsername(java.lang.String username)
Used to set the username used to connect to the database

Parameters:
username - The username used to connect to the database

setPassword

public void setPassword(java.lang.String password)
Used to set the password used to connect to the database

Parameters:
password - The password used to connect to the database

dropTable

public boolean dropTable(java.sql.Connection connection,
                         java.lang.String tableName)
This is called to delete a table from the database

Specified by:
dropTable in interface IDatabase
Parameters:
connection - The connection to the database
tableName - The table to delete
Returns:
True if it was successful, otherwise false;

getStatement

public java.sql.PreparedStatement getStatement(java.sql.Connection connection,
                                               java.lang.String sql)
                                        throws java.sql.SQLException
This is used to create a PreparedStatement from the give SQL. This is useful as different implementations of the interface can translate the SQL so that it is under stood by the database. The SQL should be in the format of MySQL SQL.

Specified by:
getStatement in interface IDatabase
Parameters:
connection - A connection to the database
sql - The statements sql
Returns:
A Prepared Statement
Throws:
java.sql.SQLException - Thrown if their is a problem creating the statement
See Also:
PreparedStatement

executeSQL

public void executeSQL(java.sql.Connection connection,
                       java.lang.String sql)
                throws java.sql.SQLException
This is used to execute a simple SQL statement on the database.

Specified by:
executeSQL in interface IDatabase
Parameters:
connection - a connection to be re-used, useful for running a series of updates as a transaction
sql - the SQL to execute on the database
Throws:
java.sql.SQLException - Thrown if their is a problem talking to the database