public class MariaDbDataSource extends Object implements DataSource, ConnectionPoolDataSource, XADataSource
Constructor and Description |
---|
MariaDbDataSource()
Default constructor. hostname will be localhost, port 3306.
|
MariaDbDataSource(String url) |
MariaDbDataSource(String hostname,
int port,
String database)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
Connection |
getConnection()
Attempts to establish a connection with the data source that this
DataSource object represents. |
Connection |
getConnection(String username,
String password)
Attempts to establish a connection with the data source that this
DataSource object represents. |
String |
getDatabaseName()
Gets the name of the database.
|
int |
getLoginTimeout()
Gets the maximum time in seconds that this data source can wait while attempting to connect to a database.
|
PrintWriter |
getLogWriter()
Retrieves the log writer for this
DataSource object. |
Logger |
getParentLogger() |
PooledConnection |
getPooledConnection()
Attempts to establish a physical database connection that can
be used as a pooled connection.
|
PooledConnection |
getPooledConnection(String user,
String password)
Attempts to establish a physical database connection that can
be used as a pooled connection.
|
int |
getPort()
Returns the port number.
|
int |
getPortNumber()
Returns the port number.
|
String |
getServerName()
Returns the name of the database server.
|
protected UrlParser |
getUrlParser()
For testing purpose only.
|
String |
getUser()
Gets the username.
|
String |
getUserName()
Gets the username.
|
XAConnection |
getXAConnection() |
XAConnection |
getXAConnection(String user,
String password) |
boolean |
isWrapperFor(Class<?> interfaceOrWrapper)
Returns true if this either implements the interface argument or is directly or indirectly a wrapper for an
object that does.
|
void |
setDatabaseName(String dbName)
Sets the database name.
|
void |
setLoginTimeout(int seconds)
Sets the maximum time in seconds that this data source will wait while attempting to connect to a database.
|
void |
setLogWriter(PrintWriter out)
Sets the log writer for this
DataSource object to the given java.io.PrintWriter
object. |
void |
setPassword(String pass)
Sets the password.
|
void |
setPort(int port)
Sets the database port.
|
void |
setPortNumber(int port)
Sets the port number.
|
void |
setProperties(String properties) |
void |
setServerName(String serverName)
Sets the server name.
|
void |
setUrl(String url)
Sets the connection string URL.
|
void |
setURL(String url)
Deprecated.
since 1.3.0 use setUrl method instead
|
void |
setUser(String userName)
Sets the username.
|
void |
setUserName(String userName)
Sets the username.
|
<T> T |
unwrap(Class<T> iface)
Returns an object that implements the given interface to allow access to non-standard methods, or standard
methods not exposed by the proxy.
|
public MariaDbDataSource(String hostname, int port, String database)
hostname
- hostname (ipv4, ipv6, dns name)port
- server portdatabase
- database namepublic MariaDbDataSource(String url) throws SQLException
SQLException
public MariaDbDataSource()
public String getDatabaseName()
public void setDatabaseName(String dbName)
dbName
- the name of the databasepublic String getUser()
public void setUser(String userName)
userName
- the usernamepublic String getUserName()
public void setUserName(String userName)
userName
- the usernamepublic void setPassword(String pass)
pass
- the passwordpublic int getPort()
public void setPort(int port)
port
- the portpublic int getPortNumber()
public void setPortNumber(int port)
port
- the portsetPort(int)
public void setProperties(String properties)
@Deprecated public void setURL(String url) throws SQLException
url
- the connection stringSQLException
- if error in URLpublic void setUrl(String url) throws SQLException
url
- the connection stringSQLException
- if error in URLpublic String getServerName()
public void setServerName(String serverName)
serverName
- the server namepublic Connection getConnection() throws SQLException
DataSource
object represents.getConnection
in interface DataSource
SQLException
- if a database access error occurspublic Connection getConnection(String username, String password) throws SQLException
DataSource
object represents.getConnection
in interface DataSource
username
- the database user on whose behalf the connection is being madepassword
- the user's passwordSQLException
- if a database access error occurspublic PrintWriter getLogWriter() throws SQLException
DataSource
object.
The log writer is a character output stream to which all logging and tracing messages for this data source
will be printed. This includes messages printed by the methods of this object, messages printed by methods of
other objects manufactured by this object, and so on. Messages printed to a data source specific log writer are
not printed to the log writer associated with the java.sql.DriverManager
class. When a
DataSource
object is created, the log writer is initially null; in other words, the default is for
logging to be disabled.
getLogWriter
in interface CommonDataSource
SQLException
- if a database access error occurssetLogWriter(java.io.PrintWriter)
public void setLogWriter(PrintWriter out) throws SQLException
DataSource
object to the given java.io.PrintWriter
object.
The log writer is a character output stream to which all logging and tracing messages for this data source
will be printed. This includes messages printed by the methods of this object, messages printed by methods of
other objects manufactured by this object, and so on. Messages printed to a data source- specific log writer are
not printed to the log writer associated with the java.sql.DriverManager
class. When a
DataSource
object is created the log writer is initially null; in other words, the default is for
logging to be disabled.
setLogWriter
in interface CommonDataSource
out
- the new log writer; to disable logging, set to nullSQLException
- if a database access error occursgetLogWriter()
public int getLoginTimeout() throws SQLException
DataSource
object is created, the login timeout is initially zero.getLoginTimeout
in interface CommonDataSource
SQLException
- if a database access error occurs.setLoginTimeout(int)
public void setLoginTimeout(int seconds) throws SQLException
DataSource
object is created, the login timeout is initially zero.setLoginTimeout
in interface CommonDataSource
seconds
- the data source login time limitSQLException
- if a database access error occurs.getLoginTimeout()
public <T> T unwrap(Class<T> iface) throws SQLException
If the receiver implements the interface then the result is the receiver or a proxy for the receiver. If the
receiver is a wrapper and the wrapped object implements the interface then the result is the wrapped object or a
proxy for the wrapped object. Otherwise return the the result of calling unwrap
recursively on the
wrapped object or a proxy for that result. If the receiver is not a wrapper and does not implement the interface,
then an SQLException
is thrown.
unwrap
in interface Wrapper
iface
- A Class defining an interface that the result must implement.SQLException
- If no object found that implements the interfacepublic boolean isWrapperFor(Class<?> interfaceOrWrapper) throws SQLException
isWrapperFor
on the wrapped object. If this
does not implement the interface and is not a wrapper, return false. This method should be implemented as a
low-cost operation compared to unwrap
so that callers can use this method to avoid expensive
unwrap
calls that may fail. If this method returns true then calling unwrap
with the
same argument should succeed.isWrapperFor
in interface Wrapper
interfaceOrWrapper
- a Class defining an interface.SQLException
- if an error occurs while determining whether this is a wrapper for an object with
the given interface.public PooledConnection getPooledConnection() throws SQLException
getPooledConnection
in interface ConnectionPoolDataSource
PooledConnection
object that is a physical
connection to the database that this
ConnectionPoolDataSource
object representsSQLException
- if a database access error occurs
if the JDBC driver does not support
this methodpublic PooledConnection getPooledConnection(String user, String password) throws SQLException
getPooledConnection
in interface ConnectionPoolDataSource
user
- the database user on whose behalf the connection is being madepassword
- the user's passwordPooledConnection
object that is a physical
connection to the database that this
ConnectionPoolDataSource
object representsSQLException
- if a database access error occurspublic XAConnection getXAConnection() throws SQLException
getXAConnection
in interface XADataSource
SQLException
public XAConnection getXAConnection(String user, String password) throws SQLException
getXAConnection
in interface XADataSource
SQLException
public Logger getParentLogger() throws SQLFeatureNotSupportedException
getParentLogger
in interface CommonDataSource
SQLFeatureNotSupportedException
protected UrlParser getUrlParser()
Copyright © 2017. All rights reserved.