Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD

Class com.imaginary.sql.msql.MsqlDataSource

java.lang.Object
  |
  +--com.imaginary.sql.msql.MsqlDataSource
Subclasses:
MsqlPooledDataSource

public class MsqlDataSource
extends java.lang.Object
implements javax.sql.DataSource, javax.naming.Referenceable, java.io.Serializable
JDBC 2.0 standard extension data source for JNDI access to an mSQL data source. Given a JNDI-accessible naming and directory service and a registered mSQL data source, client code can access that data source using JNDI calls. To access a database called "Wibbles", you would use the following code:
 Context ctx = new InitialContext();
 DataSource ds = (DataSource)ctx.lookup("jdbc/Wibbles");
 Connection conn = ds.getConnection("borg", "");
 
You must specify the following attributes in your JNDI directory:
databaseName
The name of the mSQL database.
encoding
The character set encoding for this connection. If you don't know what that means, set it to "8859_1" and everything will work fine.
loginTimeout
This is not used yet, so set it to 0.
password
You can configure a data source with a password to use for connections, thereby not requiring individual applications to know a user name/password. Right now, this does not matter for mSQL since mSQL does not require passwords. But it might in the future.
port
The server port to which mSQL is listening. If you do not know this value, try 1114.
serverName
The name of the server on which mSQL is running.
user
The user name to use for the database connection.

Last modified $Date: 1999/07/06 05:56:00 $

Version:
$Revision: 1.3 $
Author:
George Reese (borg@imaginary.com)
See Also:
Serialized Form

Constructor Summary
MsqlDataSource()
          Constructs a new MsqlDataSource without any values.
 
Method Summary
java.sql.Connection getConnection()
          Creates an mSQL connection using the configured user name and password for the JNDI directory entry.
java.sql.Connection getConnection(java.lang.String uid, java.lang.String pw)
          Provides a database connection using a user and password not configured in the JNDI directory.
java.sql.Connection getConnection(java.util.Properties props)
          Creates a connection using the specified properties.
java.lang.String getDatabaseName()
           
java.lang.String getEncoding()
           
int getLoginTimeout()
          This feature is not implemented.
java.io.PrintWriter getLogWriter()
           
int getPort()
           
javax.naming.Reference getReference()
          Required method to support this class as a Referenceable.
java.lang.String getServerName()
           
java.lang.String getURL()
          The JDBC URL that would be used to create the same sort of connection used by this data source.
java.lang.String getUser()
           
void setDatabaseName(java.lang.String nom)
          Sets the database name.
void setEncoding(java.lang.String enc)
          Sets the encoding to use for this connection.
void setLoginTimeout(int seconds)
          This feature is not yet implemented.
void setLogWriter(java.io.PrintWriter out)
          Sets the log writer for this data source.
void setPassword(java.lang.String pass)
          Sets the password to use for connecting to the database
void setPort(int p)
          Sets the database port.
void setServerName(java.lang.String nom)
          Sets the server name.
void setUser(java.lang.String uid)
          Sets the user ID.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notifyAll, notify, toString, wait, wait, wait
 

Constructor Detail

MsqlDataSource

public MsqlDataSource()
Constructs a new MsqlDataSource without any values. It is also used by serialization.
Method Detail

getConnection

public java.sql.Connection getConnection()
                                 throws java.sql.SQLException
Creates an mSQL connection using the configured user name and password for the JNDI directory entry.
Specified by:
getConnection() in interface javax.sql.DataSource
Returns:
a database connection
Throws:
java.sql.SQLException - the data source was unable to create a database connection using the configured user and password

getConnection

public java.sql.Connection getConnection(java.lang.String uid,
                                java.lang.String pw)
                                 throws java.sql.SQLException
Provides a database connection using a user and password not configured in the JNDI directory.
Specified by:
getConnection(java.lang.String, java.lang.String) in interface javax.sql.DataSource
Parameters:
uid - the user ID to connect with
pw - the password to use for the connection
Returns:
a database connection
Throws:
java.sql.SQLException - the data source was unable to create a database connection using the specified user and password

getConnection

protected java.sql.Connection getConnection(java.util.Properties props)
                                    throws java.sql.SQLException
Creates a connection using the specified properties.
Parameters:
props - the properties to use for the connection
Returns:
a database connection
Throws:
java.sql.SQLException - a database error occurred

getDatabaseName

public java.lang.String getDatabaseName()
Returns:
the name of the mSQL database to connect to

getEncoding

public java.lang.String getEncoding()
Returns:
the character set encoding

getLogWriter

public java.io.PrintWriter getLogWriter()
                                throws java.sql.SQLException
Description copied from interface:
 
Specified by:
getLogWriter() in interface javax.sql.DataSource
Returns:
the error log.
Throws:
java.sql.SQLException - could not get a stream

getLoginTimeout

public int getLoginTimeout()
                   throws java.sql.SQLException
This feature is not implemented.
Specified by:
getLoginTimeout() in interface javax.sql.DataSource
Returns:
0
Throws:
java.sql.SQLException - this is never thrown

getPort

public int getPort()
Returns:
the mSQL port on which the database is listening.

getReference

public javax.naming.Reference getReference()
                                   throws javax.naming.NamingException
Required method to support this class as a Referenceable.
Specified by:
getReference() in interface javax.naming.Referenceable
Returns:
a reference to this object
Throws:
javax.naming.NamingException - a problem occurred constructing the reference

getServerName

public java.lang.String getServerName()
Returns:
the name of the server on which mSQL resides

getURL

public java.lang.String getURL()
The JDBC URL that would be used to create the same sort of connection used by this data source.
Returns:
the JDBC URL for this data source

getUser

public java.lang.String getUser()
Returns:
user ID for the connection

setDatabaseName

public void setDatabaseName(java.lang.String nom)
Sets the database name.
Parameters:
nom - the name of the database

setEncoding

public void setEncoding(java.lang.String enc)
Sets the encoding to use for this connection.
Parameters:
enc - the encoding

setLogWriter

public void setLogWriter(java.io.PrintWriter out)
                 throws java.sql.SQLException
Sets the log writer for this data source.
Specified by:
setLogWriter(java.io.PrintWriter) in interface javax.sql.DataSource
Parameters:
out - the new log writer
Throws:
java.sql.SQLException - this is never thrown

setLoginTimeout

public void setLoginTimeout(int seconds)
                    throws java.sql.SQLException
This feature is not yet implemented.
Specified by:
setLoginTimeout(int) in interface javax.sql.DataSource
Parameters:
seconds - ignore this
Returns:
java.sql.SQLException this is never thrown

setPassword

public void setPassword(java.lang.String pass)
Sets the password to use for connecting to the database
Parameters:
pass - the password

setPort

public void setPort(int p)
Sets the database port.
Parameters:
p - the port

setServerName

public void setServerName(java.lang.String nom)
Sets the server name.
Parameters:
nom - the server name

setUser

public void setUser(java.lang.String uid)
Sets the user ID.
Parameters:
uid - the user ID

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD