public class SimpleDataSource
extends java.lang.Object
implements javax.sql.DataSource
Connection by using DriverManager.getConnection(String, Properties).
It is assumed that this object is used only in simple applications. In production environment,
you should use the DataSource implementation that provides connection pooling.
| Modifier and Type | Field and Description |
|---|---|
protected java.lang.String |
password |
protected java.util.Properties |
properties |
protected static java.lang.String |
UNABLE_TO_ESTABLISH_CONNECTION
the
SQLState code to indicate that the this data source is unable to establish the
connection |
protected java.lang.String |
url |
protected java.lang.String |
user |
| Constructor and Description |
|---|
SimpleDataSource() |
| Modifier and Type | Method and Description |
|---|---|
void |
addProperty(java.lang.String key,
java.lang.String value)
Add a JDBC property.
|
java.sql.Connection |
getConnection() |
java.sql.Connection |
getConnection(java.lang.String user,
java.lang.String password) |
protected java.sql.Connection |
getConnectionInternal(java.util.Properties info) |
int |
getLoginTimeout() |
java.io.PrintWriter |
getLogWriter() |
java.util.logging.Logger |
getParentLogger() |
java.lang.String |
getPassword()
Returns the database password
|
java.lang.String |
getUrl()
Returns the database url.
|
java.lang.String |
getUser()
Returns the database user.
|
boolean |
isWrapperFor(java.lang.Class<?> iface) |
void |
setLoginTimeout(int seconds) |
void |
setLogWriter(java.io.PrintWriter out) |
void |
setPassword(java.lang.String password)
Sets the database password
|
void |
setUrl(java.lang.String url)
Sets the database url of the form
jdbc:subprotocol:subname. |
void |
setUser(java.lang.String user)
Sets the database user.
|
<T> T |
unwrap(java.lang.Class<T> iface) |
protected static final java.lang.String UNABLE_TO_ESTABLISH_CONNECTION
SQLState code to indicate that the this data source is unable to establish the
connectionprotected java.lang.String url
protected java.lang.String user
protected java.lang.String password
protected final java.util.Properties properties
public java.lang.String getUrl()
public void setUrl(java.lang.String url)
jdbc:subprotocol:subname.url - the database urlpublic java.lang.String getUser()
public void setUser(java.lang.String user)
user - the database userpublic java.lang.String getPassword()
public void setPassword(java.lang.String password)
password - the database passwordpublic void addProperty(java.lang.String key,
java.lang.String value)
key - the key of the propertyvalue - the value of the propertypublic int getLoginTimeout()
getLoginTimeout in interface javax.sql.CommonDataSourcepublic void setLoginTimeout(int seconds)
setLoginTimeout in interface javax.sql.CommonDataSourcepublic java.sql.Connection getConnection()
throws java.sql.SQLException
getConnection in interface javax.sql.DataSourcejava.sql.SQLExceptionpublic java.sql.Connection getConnection(java.lang.String user,
java.lang.String password)
throws java.sql.SQLException
getConnection in interface javax.sql.DataSourcejava.sql.SQLExceptionprotected java.sql.Connection getConnectionInternal(java.util.Properties info)
throws java.sql.SQLException
java.sql.SQLExceptionpublic java.io.PrintWriter getLogWriter()
throws java.sql.SQLException
getLogWriter in interface javax.sql.CommonDataSourcejava.sql.SQLExceptionpublic void setLogWriter(java.io.PrintWriter out)
throws java.sql.SQLException
setLogWriter in interface javax.sql.CommonDataSourcejava.sql.SQLExceptionpublic boolean isWrapperFor(java.lang.Class<?> iface)
throws java.sql.SQLException
isWrapperFor in interface java.sql.Wrapperjava.sql.SQLExceptionpublic <T> T unwrap(java.lang.Class<T> iface)
throws java.sql.SQLException
unwrap in interface java.sql.Wrapperjava.sql.SQLExceptionpublic java.util.logging.Logger getParentLogger()
throws java.sql.SQLFeatureNotSupportedException
getParentLogger in interface javax.sql.CommonDataSourcejava.sql.SQLFeatureNotSupportedException