ch.sahits.phpclassgenerator
Class MySQLConnection

java.lang.Object
  extended by ch.sahits.phpclassgenerator.DBConnection
      extended by ch.sahits.phpclassgenerator.MySQLConnection

public class MySQLConnection
extends DBConnection

This class handles the connection to a MySQL DB. It queries the DB for the structure of a table. Supported DBs are

Version:
1.0 $Revision: 1.3 $ changed by $Author: hotzst $ at $Date: 2007/11/18 09:18:43 $
Author:
Andi Hotz, (c) 2007

Field Summary
 
Fields inherited from class ch.sahits.phpclassgenerator.DBConnection
conn, db, host, password, product, table, user
 
Constructor Summary
MySQLConnection(java.lang.String product, java.lang.String hostname, java.lang.String uname, java.lang.String pwd, java.lang.String database, java.lang.String tablename)
          Constructor initializes the connection data
 
Method Summary
protected  DBStructure getStructure()
          Query the INFORMATION_SCHEMA to retrive the metadata
protected  void loadDriver()
          check if the driver is available
private  java.lang.String[] retriveMySQLForeignKey(java.lang.String fkName)
          Retrive the foreign key of the table
private  java.lang.String[] retriveMySQLPrimaryKey(java.lang.String pkName)
          Retrive the primiry key of the table
 
Methods inherited from class ch.sahits.phpclassgenerator.DBConnection
setHost, setPassword, setProduct, setTable, setUser
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MySQLConnection

public MySQLConnection(java.lang.String product,
                       java.lang.String hostname,
                       java.lang.String uname,
                       java.lang.String pwd,
                       java.lang.String database,
                       java.lang.String tablename)
                throws java.sql.SQLException
Constructor initializes the connection data

Parameters:
product - what kind of DB (MySQL, PostgeSQL, Oracle, Derby, MS SQL Server, ...)
hostname - of the db eg. localhost
uname - user name to connect to the DB
pwd - password of the user
database - or schema of the table
tablename - table name
Throws:
java.sql.SQLException - Connecting failed probably due to incorrect input
Method Detail

getStructure

protected DBStructure getStructure()
                            throws java.sql.SQLException
Query the INFORMATION_SCHEMA to retrive the metadata

Specified by:
getStructure in class DBConnection
Returns:
DBStructure
Throws:
java.sql.SQLException

retriveMySQLPrimaryKey

private java.lang.String[] retriveMySQLPrimaryKey(java.lang.String pkName)
                                           throws java.sql.SQLException
Retrive the primiry key of the table

Parameters:
pkName - Primary key name
Returns:
String array with column names
Throws:
java.sql.SQLException

retriveMySQLForeignKey

private java.lang.String[] retriveMySQLForeignKey(java.lang.String fkName)
                                           throws java.sql.SQLException
Retrive the foreign key of the table

Parameters:
fkName - Foreign key name
Returns:
String array with column names
Throws:
java.sql.SQLException
java.sql.SQLException

loadDriver

protected void loadDriver()
check if the driver is available

Specified by:
loadDriver in class DBConnection