sg.edu.nus.dbconnection
Class DBServer

java.lang.Object
  extended by sg.edu.nus.dbconnection.DBServer

public class DBServer
extends java.lang.Object

Create connection and execute query over underlying DBMS.


Constructor Summary
DBServer()
          Constructor without parameters
DBServer(java.lang.String dbName)
           
DBServer(java.lang.String driver, java.lang.String url, java.lang.String userName, java.lang.String password, java.lang.String port, java.lang.String dbName)
          Constructor with parameters
 
Method Summary
 void close()
          Close connection to the database server
 void createConnection(java.lang.String driver, java.lang.String url, java.lang.String userName, java.lang.String password, java.lang.String port, java.lang.String dbName)
          Establish a connection
 java.sql.PreparedStatement createPreparedStatement(java.lang.String sql)
          Create an SQL statement with parameters, which are updated later
 java.sql.PreparedStatement createPreparedStatement(java.lang.String sql, int rsType, int rsConcurrency)
          Create an SQL statement with parameters, which are updated later
 java.sql.Statement createStatement()
          Create an SQL statement for executing later
 java.sql.Statement createStatement(int rsType, int rsConcurrency)
          Create an SQL statement for executing later
 void execute(java.lang.String ddlStatement)
          Execute a SQL DDL statement
 java.sql.ResultSet executeQuery(java.lang.String sqlstatement)
          Execute a query, return a result set
 DBServer getAdditionalConnection()
          Get an additional connection for nested queries
 java.sql.Connection getConnection()
          Get connection
 java.util.Vector<java.lang.String> getExportedKeys(java.lang.String primaryTable)
          Get exported keys
 java.util.Vector<java.lang.String> getIndexes(java.lang.String tableName)
          Get indexes of a table
 java.lang.String getMySQLFilepath(java.lang.String absPath)
          Retrieve file path for creating tempt files
 java.util.Vector<java.lang.String> getPrimaryKey(java.lang.String tableName)
          Get primary key of a table
 java.util.Vector<java.lang.String> getTableDescription(java.lang.String tableName)
          Deprecated.  
 java.util.Vector<java.lang.String> getTables()
          Get all tables in the database
 java.sql.ResultSetMetaData getTableSchema(java.lang.String table_name)
          Retrieve table description
 boolean hasColumn(java.lang.String tableName, java.lang.String columnName)
          Check if a column exists in a table
 boolean hasTable(java.lang.String tableName)
          Check if a table exists in the database
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DBServer

public DBServer()
Constructor without parameters


DBServer

public DBServer(java.lang.String dbName)

DBServer

public DBServer(java.lang.String driver,
                java.lang.String url,
                java.lang.String userName,
                java.lang.String password,
                java.lang.String port,
                java.lang.String dbName)
Constructor with parameters

Parameters:
server -
userName -
password -
port -
dbName -
Method Detail

createConnection

public void createConnection(java.lang.String driver,
                             java.lang.String url,
                             java.lang.String userName,
                             java.lang.String password,
                             java.lang.String port,
                             java.lang.String dbName)
Establish a connection

Parameters:
server -
userName -
password -
port -
dbName -

getAdditionalConnection

public DBServer getAdditionalConnection()
Get an additional connection for nested queries

Returns:

close

public void close()
Close connection to the database server


executeQuery

public java.sql.ResultSet executeQuery(java.lang.String sqlstatement)
Execute a query, return a result set

Parameters:
sqlstatement -
Returns:

execute

public final void execute(java.lang.String ddlStatement)
                   throws java.sql.SQLException
Execute a SQL DDL statement

Parameters:
DDL - statement
Throws:
java.sql.SQLException

createStatement

public java.sql.Statement createStatement()
Create an SQL statement for executing later

Returns:

createStatement

public java.sql.Statement createStatement(int rsType,
                                          int rsConcurrency)
Create an SQL statement for executing later

Parameters:
rsType -
rsConcurrency -
Returns:

createPreparedStatement

public java.sql.PreparedStatement createPreparedStatement(java.lang.String sql)
Create an SQL statement with parameters, which are updated later

Parameters:
sql -
Returns:

createPreparedStatement

public java.sql.PreparedStatement createPreparedStatement(java.lang.String sql,
                                                          int rsType,
                                                          int rsConcurrency)
Create an SQL statement with parameters, which are updated later

Parameters:
sql -
rsType -
rsConcurrency -
Returns:

getTables

public java.util.Vector<java.lang.String> getTables()
Get all tables in the database

Returns:

hasTable

public boolean hasTable(java.lang.String tableName)
Check if a table exists in the database

Parameters:
tableName -
Returns:

hasColumn

public boolean hasColumn(java.lang.String tableName,
                         java.lang.String columnName)
Check if a column exists in a table

Parameters:
columnName -
Returns:

getTableSchema

public java.sql.ResultSetMetaData getTableSchema(java.lang.String table_name)
                                          throws java.sql.SQLException
Retrieve table description

Parameters:
table_name -
Throws:
java.sql.SQLException

getTableDescription

public java.util.Vector<java.lang.String> getTableDescription(java.lang.String tableName)
Deprecated. 

Retrieve table description

Parameters:
tableName -
Returns:

getPrimaryKey

public java.util.Vector<java.lang.String> getPrimaryKey(java.lang.String tableName)
Get primary key of a table

Parameters:
tableName -
Returns:

getExportedKeys

public java.util.Vector<java.lang.String> getExportedKeys(java.lang.String primaryTable)
Get exported keys

Parameters:
primaryTable -
Returns:

getMySQLFilepath

public java.lang.String getMySQLFilepath(java.lang.String absPath)
Retrieve file path for creating tempt files

Parameters:
absPath -
Returns:

getIndexes

public java.util.Vector<java.lang.String> getIndexes(java.lang.String tableName)
Get indexes of a table

Parameters:
tableName -
Returns:

getConnection

public java.sql.Connection getConnection()
Get connection

Returns: