Package com.mysql.cj.jdbc
Class MysqlDataSource
java.lang.Object
com.mysql.cj.conf.DefaultPropertySet
com.mysql.cj.jdbc.JdbcPropertySetImpl
com.mysql.cj.jdbc.MysqlDataSource
- All Implemented Interfaces:
PropertySet,JdbcPropertySet,java.io.Serializable,java.sql.Wrapper,javax.naming.Referenceable,javax.sql.CommonDataSource,javax.sql.DataSource
- Direct Known Subclasses:
MysqlConnectionPoolDataSource,MysqlXADataSource
public class MysqlDataSource extends JdbcPropertySetImpl implements javax.sql.DataSource, javax.naming.Referenceable, java.io.Serializable, JdbcPropertySet
A JNDI DataSource for a Mysql JDBC connection
- See Also:
- Serialized Form
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.StringdatabaseNameDatabase Nameprotected java.lang.Stringdescriptionprotected java.lang.StringencodingCharacter Encodingprotected booleanexplicitPortWas the port explicitly set?protected booleanexplicitUrlShould we construct the URL, or has it been set explicitly?protected java.lang.StringhostNameHostnameprotected java.io.PrintWriterlogWriterLog streamprotected static NonRegisteringDrivermysqlDriverThe driver to create connections withprotected java.lang.StringpasswordPasswordprotected intportPort numberprotected java.lang.StringprofileSQLStringThe profileSQL propertyprotected java.lang.StringurlThe JDBC URLprotected java.lang.StringuserUser name -
Constructor Summary
Constructors Constructor Description MysqlDataSource()Default no-arg constructor for Serialization -
Method Summary
Modifier and Type Method Description java.util.PropertiesexposeAsProperties()protected booleangetBooleanRuntimeProperty(java.lang.String name)Used in properties getters added by instrumentation.java.sql.ConnectiongetConnection()java.sql.ConnectiongetConnection(java.lang.String userID, java.lang.String pass)protected java.sql.ConnectiongetConnection(java.util.Properties props)Creates a connection using the specified properties.java.lang.StringgetDatabaseName()Gets the name of the databasejava.lang.StringgetDescription()protected java.lang.StringgetEnumRuntimeProperty(java.lang.String name)Used in properties getters added by instrumentation.protected intgetIntegerRuntimeProperty(java.lang.String name)Used in properties getters added by instrumentation.intgetLoginTimeout()java.io.PrintWritergetLogWriter()protected longgetLongRuntimeProperty(java.lang.String name)Used in properties getters added by instrumentation.protected intgetMemorySizeRuntimeProperty(java.lang.String name)Used in properties getters added by instrumentation.java.util.logging.LoggergetParentLogger()java.lang.StringgetPassword()Get the password.intgetPort()Returns the port numberintgetPortNumber()Returns the port numberjavax.naming.ReferencegetReference()Required method to support this class as aReferenceable.java.lang.StringgetServerName()Returns the name of the database serverprotected java.lang.StringgetStringRuntimeProperty(java.lang.String name)Used in properties getters added by instrumentation.java.lang.StringgetUrl()Returns the JDBC URL that will be used to create the database connection.java.lang.StringgetURL()Returns the URL for this connectionjava.lang.StringgetUser()Returns the configured user for this connectionbooleanisWrapperFor(java.lang.Class<?> iface)protected voidsetBooleanRuntimeProperty(java.lang.String name, boolean value)Used in properties setters added by instrumentation.voidsetDatabaseName(java.lang.String dbName)Sets the database name.voidsetDescription(java.lang.String value)protected voidsetEnumRuntimeProperty(java.lang.String name, java.lang.String value)Used in properties setters added by instrumentation.protected voidsetIntegerRuntimeProperty(java.lang.String name, int value)Used in properties setters added by instrumentation.voidsetLoginTimeout(int seconds)voidsetLogWriter(java.io.PrintWriter output)protected voidsetLongRuntimeProperty(java.lang.String name, long value)Used in properties setters added by instrumentation.protected voidsetMemorySizeRuntimeProperty(java.lang.String name, int value)Used in properties setters added by instrumentation.voidsetPassword(java.lang.String pass)Sets the passwordvoidsetPort(int p)Sets the database port.voidsetPortNumber(int p)Sets the port numbervoidsetPropertiesViaRef(javax.naming.Reference 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).voidsetServerName(java.lang.String serverName)Sets the server name.protected voidsetStringRuntimeProperty(java.lang.String name, java.lang.String value)Used in properties setters added by instrumentation.voidsetUrl(java.lang.String url)This method is used by the app server to set the url string specified within the datasource deployment descriptor.voidsetURL(java.lang.String url)Sets the URL for this connectionvoidsetUser(java.lang.String userID)Sets the user ID.<T> Tunwrap(java.lang.Class<T> iface)Methods inherited from class com.mysql.cj.jdbc.JdbcPropertySetImpl
exposeAsDriverPropertyInfo, postInitializationMethods inherited from class com.mysql.cj.conf.DefaultPropertySet
addProperty, getBooleanProperty, getBooleanProperty, getEnumProperty, getEnumProperty, getIntegerProperty, getIntegerProperty, getLongProperty, getLongProperty, getMemorySizeProperty, getMemorySizeProperty, getProperty, getProperty, getStringProperty, getStringProperty, initializeProperties, removeProperty, removeProperty, resetMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.mysql.cj.conf.PropertySet
addProperty, getBooleanProperty, getBooleanProperty, getEnumProperty, getEnumProperty, getIntegerProperty, getIntegerProperty, getLongProperty, getLongProperty, getMemorySizeProperty, getMemorySizeProperty, getProperty, getProperty, getStringProperty, getStringProperty, initializeProperties, postInitialization, removeProperty, removeProperty, reset
-
Field Details
-
mysqlDriver
The driver to create connections with -
logWriter
protected transient java.io.PrintWriter logWriterLog stream -
databaseName
protected java.lang.String databaseNameDatabase Name -
encoding
protected java.lang.String encodingCharacter Encoding -
url
protected java.lang.String urlThe JDBC URL -
explicitUrl
protected boolean explicitUrlShould we construct the URL, or has it been set explicitly? -
hostName
protected java.lang.String hostNameHostname -
port
protected int portPort number -
explicitPort
protected boolean explicitPortWas the port explicitly set? -
user
protected java.lang.String userUser name -
password
protected java.lang.String passwordPassword -
profileSQLString
protected java.lang.String profileSQLStringThe profileSQL property -
description
protected java.lang.String description
-
-
Constructor Details
-
MysqlDataSource
public MysqlDataSource()Default no-arg constructor for Serialization
-
-
Method Details
-
getConnection
public java.sql.Connection getConnection() throws java.sql.SQLException- Specified by:
getConnectionin interfacejavax.sql.DataSource- Throws:
java.sql.SQLException
-
getConnection
public java.sql.Connection getConnection(java.lang.String userID, java.lang.String pass) throws java.sql.SQLException- Specified by:
getConnectionin interfacejavax.sql.DataSource- Throws:
java.sql.SQLException
-
getDescription
public java.lang.String getDescription() -
setDescription
public void setDescription(java.lang.String value) -
setDatabaseName
public void setDatabaseName(java.lang.String dbName)Sets the database name.- Parameters:
dbName- the name of the database
-
getDatabaseName
public java.lang.String getDatabaseName()Gets the name of the database- Returns:
- the name of the database for this data source
-
setLogWriter
public void setLogWriter(java.io.PrintWriter output) throws java.sql.SQLException- Specified by:
setLogWriterin interfacejavax.sql.CommonDataSource- Specified by:
setLogWriterin interfacejavax.sql.DataSource- Throws:
java.sql.SQLException
-
getLogWriter
public java.io.PrintWriter getLogWriter()- Specified by:
getLogWriterin interfacejavax.sql.CommonDataSource- Specified by:
getLogWriterin interfacejavax.sql.DataSource
-
setLoginTimeout
public void setLoginTimeout(int seconds) throws java.sql.SQLException- Specified by:
setLoginTimeoutin interfacejavax.sql.CommonDataSource- Specified by:
setLoginTimeoutin interfacejavax.sql.DataSource- Throws:
java.sql.SQLException
-
getLoginTimeout
public int getLoginTimeout()- Specified by:
getLoginTimeoutin interfacejavax.sql.CommonDataSource- Specified by:
getLoginTimeoutin interfacejavax.sql.DataSource
-
setPassword
public void setPassword(java.lang.String pass)Sets the password- Parameters:
pass- the password
-
getPassword
public java.lang.String getPassword()Get the password.- Returns:
- password
-
setPort
public void setPort(int p)Sets the database port.- Parameters:
p- the port
-
getPort
public int getPort()Returns the port number- Returns:
- the port number
-
setPortNumber
public void setPortNumber(int p)Sets the port number- Parameters:
p- the port
-
getPortNumber
public int getPortNumber()Returns the port number- Returns:
- the port number
-
setPropertiesViaRef
public void setPropertiesViaRef(javax.naming.Reference ref) throws java.sql.SQLExceptionInitializes 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- The JNDI Reference that holds RefAddrs for all properties- Throws:
java.sql.SQLException- if error occurs
-
getReference
public javax.naming.Reference getReference() throws javax.naming.NamingExceptionRequired method to support this class as aReferenceable.- Specified by:
getReferencein interfacejavax.naming.Referenceable- Returns:
- a Reference to this data source
- Throws:
javax.naming.NamingException- if a JNDI error occurs
-
setServerName
public void setServerName(java.lang.String serverName)Sets the server name.- Parameters:
serverName- the server name
-
getServerName
public java.lang.String getServerName()Returns the name of the database server- Returns:
- the name of the database server
-
setURL
public void setURL(java.lang.String url)Sets the URL for this connection- Parameters:
url- the URL for this connection
-
getURL
public java.lang.String getURL()Returns the URL for this connection- Returns:
- the URL for this connection
-
setUrl
public void setUrl(java.lang.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- url to be used within driver.connect
-
getUrl
public java.lang.String getUrl()Returns the JDBC URL that will be used to create the database connection.- Returns:
- the URL for this connection
-
setUser
public void setUser(java.lang.String userID)Sets the user ID.- Parameters:
userID- the User ID
-
getUser
public java.lang.String getUser()Returns the configured user for this connection- Returns:
- the user for this connection
-
getConnection
protected java.sql.Connection getConnection(java.util.Properties props) throws java.sql.SQLExceptionCreates a connection using the specified properties.- Parameters:
props- the properties to connect with- Returns:
- a connection to the database
- Throws:
java.sql.SQLException- if an error occurs
-
getParentLogger
public java.util.logging.Logger getParentLogger() throws java.sql.SQLFeatureNotSupportedException- Specified by:
getParentLoggerin interfacejavax.sql.CommonDataSource- Throws:
java.sql.SQLFeatureNotSupportedException
-
unwrap
public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException- Specified by:
unwrapin interfacejava.sql.Wrapper- Throws:
java.sql.SQLException
-
isWrapperFor
public boolean isWrapperFor(java.lang.Class<?> iface) throws java.sql.SQLException- Specified by:
isWrapperForin interfacejava.sql.Wrapper- Throws:
java.sql.SQLException
-
getStringRuntimeProperty
protected java.lang.String getStringRuntimeProperty(java.lang.String name) throws java.sql.SQLExceptionUsed in properties getters added by instrumentation.- Parameters:
name- property name property name- Returns:
- property value
- Throws:
java.sql.SQLException- if error occurs
-
setStringRuntimeProperty
protected void setStringRuntimeProperty(java.lang.String name, java.lang.String value) throws java.sql.SQLExceptionUsed in properties setters added by instrumentation.- Parameters:
name- property namevalue- value- Throws:
java.sql.SQLException- if error occurs
-
getBooleanRuntimeProperty
protected boolean getBooleanRuntimeProperty(java.lang.String name) throws java.sql.SQLExceptionUsed in properties getters added by instrumentation.- Parameters:
name- property name- Returns:
- property value
- Throws:
java.sql.SQLException- if error occurs
-
setBooleanRuntimeProperty
protected void setBooleanRuntimeProperty(java.lang.String name, boolean value) throws java.sql.SQLExceptionUsed in properties setters added by instrumentation.- Parameters:
name- property namevalue- value- Throws:
java.sql.SQLException- if error occurs
-
getIntegerRuntimeProperty
protected int getIntegerRuntimeProperty(java.lang.String name) throws java.sql.SQLExceptionUsed in properties getters added by instrumentation.- Parameters:
name- property name- Returns:
- property value
- Throws:
java.sql.SQLException- if error occurs
-
setIntegerRuntimeProperty
protected void setIntegerRuntimeProperty(java.lang.String name, int value) throws java.sql.SQLExceptionUsed in properties setters added by instrumentation.- Parameters:
name- property namevalue- value- Throws:
java.sql.SQLException- if error occurs
-
getLongRuntimeProperty
protected long getLongRuntimeProperty(java.lang.String name) throws java.sql.SQLExceptionUsed in properties getters added by instrumentation.- Parameters:
name- property name- Returns:
- property value
- Throws:
java.sql.SQLException- if error occurs
-
setLongRuntimeProperty
protected void setLongRuntimeProperty(java.lang.String name, long value) throws java.sql.SQLExceptionUsed in properties setters added by instrumentation.- Parameters:
name- property namevalue- value- Throws:
java.sql.SQLException- if error occurs
-
getMemorySizeRuntimeProperty
protected int getMemorySizeRuntimeProperty(java.lang.String name) throws java.sql.SQLExceptionUsed in properties getters added by instrumentation.- Parameters:
name- property name- Returns:
- property value
- Throws:
java.sql.SQLException- if error occurs
-
setMemorySizeRuntimeProperty
protected void setMemorySizeRuntimeProperty(java.lang.String name, int value) throws java.sql.SQLExceptionUsed in properties setters added by instrumentation.- Parameters:
name- property namevalue- value- Throws:
java.sql.SQLException- if error occurs
-
getEnumRuntimeProperty
protected java.lang.String getEnumRuntimeProperty(java.lang.String name) throws java.sql.SQLExceptionUsed in properties getters added by instrumentation.- Parameters:
name- property name- Returns:
- property value
- Throws:
java.sql.SQLException- if error occurs
-
setEnumRuntimeProperty
protected void setEnumRuntimeProperty(java.lang.String name, java.lang.String value) throws java.sql.SQLExceptionUsed in properties setters added by instrumentation.- Parameters:
name- property namevalue- value- Throws:
java.sql.SQLException- if error occurs
-
exposeAsProperties
public java.util.Properties exposeAsProperties()- Specified by:
exposeAsPropertiesin interfacePropertySet- Overrides:
exposeAsPropertiesin classDefaultPropertySet
-