Connector/J (JDBC) Reference
2055
Any other parameters are treated as host-specific properties that follow the conventions of the JDBC
URL properties. This now allows per-host overrides of any configuration property for multi-host
connections (that is, when using failover, load balancing, or replication). Limit the overrides to user,
password, network timeouts and statement and metadata cache sizes; the results of other per-host
overrides are not defined.
Initial Database for Connection
If the database is not specified, the connection is made with no default database. In this case, either
call the
setCatalog()
method on the Connection instance, or fully specify table names using the
database name (that is,
SELECT dbname.tablename.colname FROM dbname.tablename...
) in
your SQL. Opening a connection without specifying the database to use is generally only useful when
building tools that work with multiple databases, such as GUI database managers.
Note
Always use the
Connection.setCatalog()
method to specify the desired
database in JDBC applications, rather than the
USE database
statement.
Failover Support
MySQL Connector/J has failover support. This enables the driver to fail over to any number of
slave hosts and still perform read-only queries. Failover only happens when the connection is in
an
autoCommit(true)
state, because failover cannot happen reliably when a
transaction
is in
progress. Most application servers and connection pools set
autoCommit
to
true
at the end of every
transaction/connection use.
The failover functionality has the following behavior:
• If the URL property
autoReconnect
is
false
: Failover only happens at connection initialization,
and failback occurs when the driver determines that the first host has become available again.
• If the URL property
autoReconnect
is
true
: Failover happens when the driver determines that
the connection has failed (checked before every query), and falls back to the first host when it
determines that the host has become available again (after
queriesBeforeRetryMaster
queries
have been issued).
In either case, whenever you are connected to a “failed-over” server, the connection is set to read-only
state, so queries that attempt to modify data will throw exceptions (the query will never be processed
by the MySQL server).
Setting Configuration Properties
Configuration properties define how Connector/J will make a connection to a MySQL server. Unless
otherwise noted, properties can be set for a
DataSource
object or for a
Connection
object.
Configuration properties can be set in one of the following ways:
• Using the
set*()
methods on MySQL implementations of
java.sql.DataSource
(which is the
preferred method when using implementations of
java.sql.DataSource
):
•
com.mysql.jdbc.jdbc2.optional.MysqlDataSource
•
com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource
• As a key/value pair in the
java.util.Properties
instance passed to
DriverManager.getConnection()
or
Driver.connect()
• As a JDBC URL parameter in the URL given to
java.sql.DriverManager.getConnection()
,
java.sql.Driver.connect()
or the MySQL implementations of the
javax.sql.DataSource
setURL()
method.
Summary of Contents for 5.0
Page 1: ...MySQL 5 0 Reference Manual ...
Page 18: ...xviii ...
Page 60: ...40 ...
Page 396: ...376 ...
Page 578: ...558 ...
Page 636: ...616 ...
Page 844: ...824 ...
Page 1234: ...1214 ...
Page 1427: ...MySQL Proxy Scripting 1407 ...
Page 1734: ...1714 ...
Page 1752: ...1732 ...
Page 1783: ...Configuring Connector ODBC 1763 ...
Page 1793: ...Connector ODBC Examples 1773 ...
Page 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Page 2850: ...2830 ...
Page 2854: ...2834 ...
Page 2928: ...2908 ...
Page 3000: ...2980 ...
Page 3122: ...3102 ...
Page 3126: ...3106 ...
Page 3174: ...3154 ...
Page 3232: ...3212 ...