Driver Class Name and jdbc url Format

Source: Internet
Author: User
Tags failover
The name of the class that implements java. SQL. driver in MySQL Connector/J is 'com. mysql. jdbc. driver '. the 'org. gjt. mm. mysql. driver 'class name is also usable to remain backwards-compatible with MM. mySQL. you shoshould use this class name when registering the driver, or when otherwise login ing software to use MySQL Connector/J.
The jdbc url format for MySQL Connector/J is as follows, with items in square brackets ([,]) being optional:
Jdbc: mysql: // [host] [, failoverhost...] [: port]/[database] [? PropertyName1] [= propertyValue1] [& propertyName2] [= propertyValue2]...
If the hostname is not specified, it defaults to '2017. 0.0.1 '. If the port is not specified, it defaults to '2016', the default port number for MySQL servers.
Starting with version 3.0.12 and 3.1.2, Connector/J supports multiple hosts with ports, separated by commas:
Jdbc: mysql: // [host: port], [host: port].../[database] [? PropertyName1] [= propertyValue1] [& propertyName2] [= propertyValue2]...
If the database is not specified, the connection will be made with no 'current' database. in this case, you will need to either call the 'setcatalog () 'method on the Connection instance, issue a 'use dbname' query or fully-specify table names using the database name (I. e. 'select dbname. tablename. colname FROM dbname. tablename... ') in your SQL. not specifying the database to use upon connection is generally only useful when building tools that work with multiple databases, such as GUI database managers.
MySQL Connector/J has fail-over support. this allows the driver to fail-over to any number of "slave" hosts and still perform read-only queries. fail-over only happens when the connection is in an autoCommit (true) state, because fail-over can not happen reliably when a transaction is in progress. most good application servers and connection pools set autoCommit to 'True' at the end of every transaction/connection use. the fail-over 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 (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 will be set to read-only state, so queries that wocould modify data will have privileges tions thrown (the query will never be processed by the MySQL server ).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.