Top Description Fields Constructors Methods
com.mysql.cj.jdbc

public Class MysqlDataSource

extends JdbcPropertySetImpl
implements DataSource, Referenceable, Serializable, JdbcPropertySet
Class Inheritance
All Implemented Interfaces
com.mysql.cj.jdbc.JdbcPropertySet, com.mysql.cj.conf.PropertySet, java.io.Serializable, javax.naming.Referenceable, javax.sql.DataSource, java.sql.Wrapper, javax.sql.CommonDataSource
Known Direct Subclasses
com.mysql.cj.jdbc.MysqlXADataSource, com.mysql.cj.jdbc.MysqlConnectionPoolDataSource
Imports
java.io.PrintWriter, .Serializable, java.sql.SQLException, .SQLFeatureNotSupportedException, java.util.Properties, java.util.logging.Logger, javax.naming.NamingException, .Reference, .Referenceable, .StringRefAddr, javax.sql.DataSource, com.mysql.cj.Messages, com.mysql.cj.conf.AbstractRuntimeProperty, .ConnectionUrl, .PropertyDefinitions, .PropertyKey, .RuntimeProperty, com.mysql.cj.util.StringUtils

A JNDI DataSource for a Mysql JDBC connection

Field Summary

Modifier and TypeField and Description
protected String
databaseName

Database Name

protected String
protected String
encoding

Character Encoding

protected boolean
explicitPort

Was the port explicitly set?

protected boolean
explicitUrl

Should we construct the URL, or has it been set explicitly?

protected String
hostName

Hostname

protected transient PrintWriter
logWriter

Log stream

protected static final NonRegisteringDriver
mysqlDriver

The driver to create connections with

protected String
password

Password

protected int
port

Port number

protected String
profileSQLString

The profileSQL property

pack-priv static final long
protected String
url

The JDBC URL

protected String
user

User name

Constructor Summary

AccessConstructor and Description
public
MysqlDataSource()

Default no-arg constructor for Serialization

Method Summary

Modifier and TypeMethod and Description
public Properties
protected boolean

Returns:

property value
getBooleanRuntimeProperty
(String
property name
name
)

Used in properties getters added by instrumentation.

public Connection
getConnection()

Implements javax.sql.DataSource.getConnection.

Attempts to establish a connection with the data source that this DataSource object represents.

public Connection
getConnection(String
the database user on whose behalf the connection is being made
userID
,
String
the user's password
pass
)

Implements javax.sql.DataSource.getConnection.

Attempts to establish a connection with the data source that this DataSource object represents.

protected Connection

Returns:

a connection to the database
getConnection
(Properties
the properties to connect with
props
)

Creates a connection using the specified properties.

public String

Returns:

the name of the database for this data source
getDatabaseName
()

Gets the name of the database

public String
protected String

Returns:

property value
getEnumRuntimeProperty
(String
property name
name
)

Used in properties getters added by instrumentation.

protected int

Returns:

property value
getIntegerRuntimeProperty
(String
property name
name
)

Used in properties getters added by instrumentation.

public int
getLoginTimeout()

Implements javax.sql.DataSource.getLoginTimeout.

Gets the maximum time in seconds that this data source can wait while attempting to connect to a database.

public PrintWriter
getLogWriter()

Implements javax.sql.DataSource.getLogWriter.

Retrieves the log writer for this DataSource object.

protected long

Returns:

property value
getLongRuntimeProperty
(String
property name
name
)

Used in properties getters added by instrumentation.

protected int

Returns:

property value
getMemorySizeRuntimeProperty
(String
property name
name
)

Used in properties getters added by instrumentation.

public Logger
getParentLogger()

Implements javax.sql.CommonDataSource.getParentLogger.

Return the parent Logger of all the Loggers used by this data source.

public String

Returns:

password
getPassword
()

Get the password.

public int

Returns:

the port number
getPort
()

Returns the port number

public int

Returns:

the port number
getPortNumber
()

Returns the port number

public Reference

Returns:

a Reference to this data source
getReference
()

Implements javax.naming.Referenceable.getReference.

Required method to support this class as a Referenceable.

public String

Returns:

the name of the database server
getServerName
()

Returns the name of the database server

protected String

Returns:

property value
getStringRuntimeProperty
(String
property name property name
name
)

Used in properties getters added by instrumentation.

public String

Returns:

the URL for this connection
getURL
()

Returns the URL for this connection

public String

Returns:

the URL for this connection
getUrl
()

Returns the JDBC URL that will be used to create the database connection.

public String

Returns:

the user for this connection
getUser
()

Returns the configured user for this connection

public boolean
isWrapperFor(Class<?>
a Class defining an interface.
iface
)

Implements java.sql.Wrapper.isWrapperFor.

Returns true if this either implements the interface argument or is directly or indirectly a wrapper for an object that does.

protected void
setBooleanRuntimeProperty(String
property name
name
,
boolean
value
value
)

Used in properties setters added by instrumentation.

public void
setDatabaseName(String
the name of the database
dbName
)

Sets the database name.

public void
protected void
setEnumRuntimeProperty(String
property name
name
,
String
value
value
)

Used in properties setters added by instrumentation.

protected void
setIntegerRuntimeProperty(String
property name
name
,
int
value
value
)

Used in properties setters added by instrumentation.

public void
setLoginTimeout(int
the data source login time limit
seconds
)

Implements javax.sql.DataSource.setLoginTimeout.

Sets the maximum time in seconds that this data source will wait while attempting to connect to a database.

public void
setLogWriter(PrintWriter
the new log writer; to disable logging, set to null
output
)

Implements javax.sql.DataSource.setLogWriter.

Sets the log writer for this DataSource object to the given java.io.PrintWriter object.

protected void
setLongRuntimeProperty(String
property name
name
,
long
value
value
)

Used in properties setters added by instrumentation.

protected void
setMemorySizeRuntimeProperty(String
property name
name
,
int
value
value
)

Used in properties setters added by instrumentation.

public void
setPassword(String
the password
pass
)

Sets the password

public void
setPort(int
the port
p
)

Sets the database port.

public void
setPortNumber(int
the port
p
)

Sets the port number

public void
setPropertiesViaRef(Reference
The JNDI Reference that holds RefAddrs for all properties
ref
)

Initializes driver properties that come from a JNDI reference (in the case of a javax.sql.DataSource bound into some name service that doesn't handle Java objects directly).

public void
setServerName(String
the server name
serverName
)

Sets the server name.

protected void
setStringRuntimeProperty(String
property name
name
,
String
value
value
)

Used in properties setters added by instrumentation.

public void
setURL(String
the URL for this connection
url
)

Sets the URL for this connection

public void
setUrl(String
url to be used within driver.connect
url
)

This method is used by the app server to set the url string specified within the datasource deployment descriptor.

public void
setUser(String
the User ID
userID
)

Sets the user ID.

public <T> T
unwrap(Class<T>
A Class defining an interface that the result must implement.
iface
)

Implements java.sql.Wrapper.unwrap.

Returns an object that implements the given interface to allow access to non-standard methods, or standard methods not exposed by the proxy.

Inherited from com.mysql.cj.jdbc.JdbcPropertySetImpl:
exposeAsDriverPropertyInfopostInitialization

Field Detail

databaseNameback to summary
protected String databaseName

Database Name

descriptionback to summary
protected String description
encodingback to summary
protected String encoding

Character Encoding

explicitPortback to summary
protected boolean explicitPort

Was the port explicitly set?

explicitUrlback to summary
protected boolean explicitUrl

Should we construct the URL, or has it been set explicitly?

hostNameback to summary
protected String hostName

Hostname

logWriterback to summary
protected transient PrintWriter logWriter

Log stream

mysqlDriverback to summary
protected static final NonRegisteringDriver mysqlDriver

The driver to create connections with

passwordback to summary
protected String password

Password

portback to summary
protected int port

Port number

profileSQLStringback to summary
protected String profileSQLString

The profileSQL property

serialVersionUIDback to summary
pack-priv static final long serialVersionUID

Hides com.mysql.cj.jdbc.JdbcPropertySetImpl.serialVersionUID.

urlback to summary
protected String url

The JDBC URL

userback to summary
protected String user

User name

Constructor Detail

MysqlDataSourceback to summary
public MysqlDataSource()

Default no-arg constructor for Serialization

Method Detail

exposeAsPropertiesback to summary
public Properties exposeAsProperties()

Overrides com.mysql.cj.conf.DefaultPropertySet.exposeAsProperties.

Implements com.mysql.cj.conf.PropertySet.exposeAsProperties.

Annotations
@Override
getBooleanRuntimePropertyback to summary
protected boolean getBooleanRuntimeProperty(String name) throws SQLException

Used in properties getters added by instrumentation.

Parameters
name:String

property name

Returns:boolean

property value

Exceptions
SQLException:
if error occurs
getConnectionback to summary
public Connection getConnection() throws SQLException

Implements javax.sql.DataSource.getConnection.

Doc from javax.sql.DataSource.getConnection.

Attempts to establish a connection with the data source that this DataSource object represents.

Returns:Connection

a connection to the data source

Annotations
@Override
Exceptions
SQLException:
if a database access error occurs
getConnectionback to summary
public Connection getConnection(String userID, String pass) throws SQLException

Implements javax.sql.DataSource.getConnection.

Doc from javax.sql.DataSource.getConnection.

Attempts to establish a connection with the data source that this DataSource object represents.

Parameters
userID:String

the database user on whose behalf the connection is being made

pass:String

the user's password

Returns:Connection

a connection to the data source

Annotations
@Override
Exceptions
SQLException:
if a database access error occurs
getConnectionback to summary
protected Connection getConnection(Properties props) throws SQLException

Creates a connection using the specified properties.

Parameters
props:Properties

the properties to connect with

Returns:Connection

a connection to the database

Exceptions
SQLException:
if an error occurs
getDatabaseNameback to summary
public String getDatabaseName()

Gets the name of the database

Returns:String

the name of the database for this data source

getDescriptionback to summary
public String getDescription()
getEnumRuntimePropertyback to summary
protected String getEnumRuntimeProperty(String name) throws SQLException

Used in properties getters added by instrumentation.

Parameters
name:String

property name

Returns:String

property value

Exceptions
SQLException:
if error occurs
getIntegerRuntimePropertyback to summary
protected int getIntegerRuntimeProperty(String name) throws SQLException

Used in properties getters added by instrumentation.

Parameters
name:String

property name

Returns:int

property value

Exceptions
SQLException:
if error occurs
getLoginTimeoutback to summary
public int getLoginTimeout()

Implements javax.sql.DataSource.getLoginTimeout.

Doc from javax.sql.DataSource.getLoginTimeout.

Gets the maximum time in seconds that this data source can wait while attempting to connect to a database. A value of zero means that the timeout is the default system timeout if there is one; otherwise, it means that there is no timeout. When a DataSource object is created, the login timeout is initially zero.

Returns:int

Doc from javax.sql.CommonDataSource.getLoginTimeout.

the data source login time limit

Annotations
@Override
getLogWriterback to summary
public PrintWriter getLogWriter()

Implements javax.sql.DataSource.getLogWriter.

Doc from javax.sql.DataSource.getLogWriter.

Retrieves the log writer for this 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.

Returns:PrintWriter

Doc from javax.sql.CommonDataSource.getLogWriter.

the log writer for this data source or null if logging is disabled

Annotations
@Override
getLongRuntimePropertyback to summary
protected long getLongRuntimeProperty(String name) throws SQLException

Used in properties getters added by instrumentation.

Parameters
name:String

property name

Returns:long

property value

Exceptions
SQLException:
if error occurs
getMemorySizeRuntimePropertyback to summary
protected int getMemorySizeRuntimeProperty(String name) throws SQLException

Used in properties getters added by instrumentation.

Parameters
name:String

property name

Returns:int

property value

Exceptions
SQLException:
if error occurs
getParentLoggerback to summary
public Logger getParentLogger() throws SQLFeatureNotSupportedException

Implements javax.sql.CommonDataSource.getParentLogger.

Doc from javax.sql.CommonDataSource.getParentLogger.

Return the parent Logger of all the Loggers used by this data source. This should be the Logger farthest from the root Logger that is still an ancestor of all of the Loggers used by this data source. Configuring this Logger will affect all of the log messages generated by the data source. In the worst case, this may be the root Logger.

Returns:Logger

the parent Logger for this data source

Annotations
@Override
Exceptions
SQLFeatureNotSupportedException:
if the data source does not use java.util.logging
getPasswordback to summary
public String getPassword()

Get the password.

Returns:String

password

getPortback to summary
public int getPort()

Returns the port number

Returns:int

the port number

getPortNumberback to summary
public int getPortNumber()

Returns the port number

Returns:int

the port number

getReferenceback to summary
public Reference getReference() throws NamingException

Implements javax.naming.Referenceable.getReference.

Required method to support this class as a Referenceable.

Returns:Reference

a Reference to this data source

Annotations
@Override
Exceptions
NamingException:
if a JNDI error occurs
getServerNameback to summary
public String getServerName()

Returns the name of the database server

Returns:String

the name of the database server

getStringRuntimePropertyback to summary
protected String getStringRuntimeProperty(String name) throws SQLException

Used in properties getters added by instrumentation.

Parameters
name:String

property name property name

Returns:String

property value

Exceptions
SQLException:
if error occurs
getURLback to summary
public String getURL()

Returns the URL for this connection

Returns:String

the URL for this connection

getUrlback to summary
public String getUrl()

Returns the JDBC URL that will be used to create the database connection.

Returns:String

the URL for this connection

getUserback to summary
public String getUser()

Returns the configured user for this connection

Returns:String

the user for this connection

isWrapperForback to summary
public boolean isWrapperFor(Class<?> iface) throws SQLException

Implements java.sql.Wrapper.isWrapperFor.

Doc from java.sql.Wrapper.isWrapperFor.

Returns true if this either implements the interface argument or is directly or indirectly a wrapper for an object that does. Returns false otherwise. If this implements the interface then return true, else if this is a wrapper then return the result of recursively calling 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.

Parameters
iface:Class<?>

a Class defining an interface.

Returns:boolean

true if this implements the interface or directly or indirectly wraps an object that does.

Annotations
@Override
Exceptions
SQLException:
if an error occurs while determining whether this is a wrapper for an object with the given interface.
setBooleanRuntimePropertyback to summary
protected void setBooleanRuntimeProperty(String name, boolean value) throws SQLException

Used in properties setters added by instrumentation.

Parameters
name:String

property name

value:boolean

value

Exceptions
SQLException:
if error occurs
setDatabaseNameback to summary
public void setDatabaseName(String dbName)

Sets the database name.

Parameters
dbName:String

the name of the database

setDescriptionback to summary
public void setDescription(String value)
setEnumRuntimePropertyback to summary
protected void setEnumRuntimeProperty(String name, String value) throws SQLException

Used in properties setters added by instrumentation.

Parameters
name:String

property name

value:String

value

Exceptions
SQLException:
if error occurs
setIntegerRuntimePropertyback to summary
protected void setIntegerRuntimeProperty(String name, int value) throws SQLException

Used in properties setters added by instrumentation.

Parameters
name:String

property name

value:int

value

Exceptions
SQLException:
if error occurs
setLoginTimeoutback to summary
public void setLoginTimeout(int seconds) throws SQLException

Implements javax.sql.DataSource.setLoginTimeout.

Doc from javax.sql.DataSource.setLoginTimeout.

Sets the maximum time in seconds that this data source will wait while attempting to connect to a database. A value of zero specifies that the timeout is the default system timeout if there is one; otherwise, it specifies that there is no timeout. When a DataSource object is created, the login timeout is initially zero.

Parameters
seconds:int

Doc from javax.sql.CommonDataSource.setLoginTimeout.

the data source login time limit

Annotations
@Override
Exceptions
SQLException:

Doc from javax.sql.CommonDataSource.setLoginTimeout.

if a database access error occurs.

setLogWriterback to summary
public void setLogWriter(PrintWriter output) throws SQLException

Implements javax.sql.DataSource.setLogWriter.

Doc from javax.sql.DataSource.setLogWriter.

Sets the log writer for this 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.

Parameters
output:PrintWriter

Doc from javax.sql.CommonDataSource.setLogWriter.

the new log writer; to disable logging, set to null

Annotations
@Override
Exceptions
SQLException:

Doc from javax.sql.CommonDataSource.setLogWriter.

if a database access error occurs

setLongRuntimePropertyback to summary
protected void setLongRuntimeProperty(String name, long value) throws SQLException

Used in properties setters added by instrumentation.

Parameters
name:String

property name

value:long

value

Exceptions
SQLException:
if error occurs
setMemorySizeRuntimePropertyback to summary
protected void setMemorySizeRuntimeProperty(String name, int value) throws SQLException

Used in properties setters added by instrumentation.

Parameters
name:String

property name

value:int

value

Exceptions
SQLException:
if error occurs
setPasswordback to summary
public void setPassword(String pass)

Sets the password

Parameters
pass:String

the password

setPortback to summary
public void setPort(int p)

Sets the database port.

Parameters
p:int

the port

setPortNumberback to summary
public void setPortNumber(int p)

Sets the port number

Parameters
p:int

the port

setPropertiesViaRefback to summary
public void setPropertiesViaRef(Reference ref) throws SQLException

Initializes driver properties that come from a JNDI reference (in the case of a javax.sql.DataSource bound into some name service that doesn't handle Java objects directly).

Parameters
ref:Reference

The JNDI Reference that holds RefAddrs for all properties

Exceptions
SQLException:
if error occurs
setServerNameback to summary
public void setServerName(String serverName)

Sets the server name.

Parameters
serverName:String

the server name

setStringRuntimePropertyback to summary
protected void setStringRuntimeProperty(String name, String value) throws SQLException

Used in properties setters added by instrumentation.

Parameters
name:String

property name

value:String

value

Exceptions
SQLException:
if error occurs
setURLback to summary
public void setURL(String url)

Sets the URL for this connection

Parameters
url:String

the URL for this connection

setUrlback to summary
public void setUrl(String url)

This method is used by the app server to set the url string specified within the datasource deployment descriptor. It is discovered using introspection and matches if property name in descriptor is "url".

Parameters
url:String

url to be used within driver.connect

setUserback to summary
public void setUser(String userID)

Sets the user ID.

Parameters
userID:String

the User ID

unwrapback to summary
public <T> T unwrap(Class<T> iface) throws SQLException

Implements java.sql.Wrapper.unwrap.

Doc from java.sql.Wrapper.unwrap.

Returns an object that implements the given interface to allow access to non-standard methods, or standard methods not exposed by the proxy. 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.

Parameters
<T>
the type of the class modeled by this Class object
iface:Class<T>

A Class defining an interface that the result must implement.

Returns:T

an object that implements the interface. May be a proxy for the actual implementing object.

Annotations
@Override
Exceptions
SQLException:
If no object found that implements the interface