proper.database
Class Connector

java.lang.Object
  extended by proper.core.ProperObject
      extended by proper.database.Connector
All Implemented Interfaces:
ProperInterface

public class Connector
extends ProperObject

This class connects to a given SQL database (standard is MySQL).

Version:
$Revision: 1.3 $
Author:
FracPete

Field Summary
static java.lang.String MYSQL_DRIVER
          the standard driver for MySQL
static java.lang.String MYSQL_LIMIT
          the standard limit SQL statement, containing "%ROWS%" as placeholder for the number of rows
static java.lang.String MYSQL_PASSWORD
          the standard user, used with no password
static java.lang.String MYSQL_URL
          the standard url
static java.lang.String MYSQL_USER
          the standard user, used with no password
static java.lang.String ROWS
          the placeholder for the number of rows in the LIMIT string
 
Fields inherited from interface proper.core.ProperInterface
VERSION
 
Constructor Summary
Connector()
          initializes the object (it initializes with the MySQL driver)
Connector(java.lang.String url, java.lang.String database)
          connects with the MySQL-Driver to the given host/database
Connector(java.lang.String url, java.lang.String database, java.lang.String user)
          connects with the MySQL-Driver to the given host/database w/o password
Connector(java.lang.String url, java.lang.String database, java.lang.String user, java.lang.String password)
          connects with the MySQL-Driver to the given host/database with user/pw
Connector(java.lang.String driver, java.lang.String url, java.lang.String database, java.lang.String user, java.lang.String password)
          connects to the database with the given driver, url, etc.
 
Method Summary
 boolean connect()
          connects the with current parameters to the database, does an automatic disconnect
 boolean connect(java.lang.String driver, java.lang.String url, java.lang.String database, java.lang.String user, java.lang.String password)
          connects to the database with given data
 void disconnect()
          disconnects from the database
 java.sql.Connection getConnection()
          returns the connection
 java.lang.String getDatabase()
          returns the database
 java.lang.String getDriver()
          returns the driver name
 java.lang.String getLimit()
          returns the current set limit string for a select with a certain amount of rows
 java.lang.String getLimit(int count)
          returns the current set limit string for a select with the given amount of rows
 java.lang.String getPassword()
          returns the password
 java.lang.String getUrl()
          returns the url
 java.lang.String getUser()
          returns the user
 boolean isConnected()
          checks whether the connection is open or not
 void setLimit(java.lang.String limit)
          sets the String that limits the select to a number of rows, e.g.  in MySQL it is done with "LIMIT %ROWS%" and it Oracle with "WHERE ROWCOUNT <= %ROWS%"
 java.lang.String toString()
          returns parameters in a string representation
 
Methods inherited from class proper.core.ProperObject
addListener, addOutput, classInVerbose, debugprint, debugprint, debugprint, debugprint, debugprintln, debugprintln, debugprintln, debugprintln, debugprintln, getListeners, getRuntime, getVerbose, getVerboseLevel, getVerboseLevelForClass, getVerboseString, getVerboseStringForClass, notifyListener, notifyListeners, print, print, print, print, println, println, println, println, println, printMemory, removeListener, setOutput, setVerbose, setVerboseLevel, setVerboseString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MYSQL_DRIVER

public static final java.lang.String MYSQL_DRIVER
the standard driver for MySQL

See Also:
Constant Field Values

MYSQL_USER

public static final java.lang.String MYSQL_USER
the standard user, used with no password

See Also:
Constant Field Values

MYSQL_PASSWORD

public static final java.lang.String MYSQL_PASSWORD
the standard user, used with no password

See Also:
Constant Field Values

MYSQL_URL

public static final java.lang.String MYSQL_URL
the standard url

See Also:
Constant Field Values

ROWS

public static final java.lang.String ROWS
the placeholder for the number of rows in the LIMIT string

See Also:
setLimit(String), Constant Field Values

MYSQL_LIMIT

public static final java.lang.String MYSQL_LIMIT
the standard limit SQL statement, containing "%ROWS%" as placeholder for the number of rows

See Also:
ROWS, setLimit(String), Constant Field Values
Constructor Detail

Connector

public Connector()
          throws java.lang.Exception
initializes the object (it initializes with the MySQL driver)

Throws:
java.lang.Exception

Connector

public Connector(java.lang.String url,
                 java.lang.String database)
          throws java.lang.Exception
connects with the MySQL-Driver to the given host/database

Parameters:
url - the url consists of jdbc:subprotocol://host[:port]/
database - the database to use
Throws:
java.lang.Exception

Connector

public Connector(java.lang.String url,
                 java.lang.String database,
                 java.lang.String user)
          throws java.lang.Exception
connects with the MySQL-Driver to the given host/database w/o password

Parameters:
url - the url consists of jdbc:subprotocol://host[:port]/
database - the database to use
user - the user to connect as
Throws:
java.lang.Exception

Connector

public Connector(java.lang.String url,
                 java.lang.String database,
                 java.lang.String user,
                 java.lang.String password)
          throws java.lang.Exception
connects with the MySQL-Driver to the given host/database with user/pw

Parameters:
url - the url consists of jdbc:subprotocol://host[:port]/
database - the database to use
user - the user to connect as
password - the corresponding password
Throws:
java.lang.Exception

Connector

public Connector(java.lang.String driver,
                 java.lang.String url,
                 java.lang.String database,
                 java.lang.String user,
                 java.lang.String password)
          throws java.lang.Exception
connects to the database with the given driver, url, etc.

Parameters:
driver - the class to use as driver
url - the url consists of jdbc:subprotocol://host[:port]/
database - the database to use
user - the user to connect as
password - the corresponding password
Throws:
java.lang.Exception
Method Detail

connect

public boolean connect()
connects the with current parameters to the database, does an automatic disconnect


connect

public boolean connect(java.lang.String driver,
                       java.lang.String url,
                       java.lang.String database,
                       java.lang.String user,
                       java.lang.String password)
connects to the database with given data

Parameters:
driver - the class to use as driver
url - the url consists of jdbc:subprotocol://host[:port]/
database - the database to use
user - the user to connect as
password - the corresponding password
Returns:
whether successful or not

disconnect

public void disconnect()
                throws java.lang.Exception
disconnects from the database

Throws:
java.lang.Exception

isConnected

public boolean isConnected()
                    throws java.lang.Exception
checks whether the connection is open or not

Throws:
java.lang.Exception

getDriver

public java.lang.String getDriver()
returns the driver name


getUrl

public java.lang.String getUrl()
returns the url


getDatabase

public java.lang.String getDatabase()
returns the database


getUser

public java.lang.String getUser()
returns the user


getPassword

public java.lang.String getPassword()
returns the password


getConnection

public java.sql.Connection getConnection()
returns the connection


setLimit

public void setLimit(java.lang.String limit)
sets the String that limits the select to a number of rows, e.g.  in MySQL it is done with "LIMIT %ROWS%" and it Oracle with "WHERE ROWCOUNT <= %ROWS%"

See Also:
MYSQL_LIMIT, ROWS

getLimit

public java.lang.String getLimit()
returns the current set limit string for a select with a certain amount of rows

See Also:
MYSQL_LIMIT, ROWS

getLimit

public java.lang.String getLimit(int count)
returns the current set limit string for a select with the given amount of rows

See Also:
MYSQL_LIMIT, ROWS

toString

public java.lang.String toString()
returns parameters in a string representation

Overrides:
toString in class ProperObject