Re: How do I form my database URL ?
Posted by: Mark Matthews
Date: January 07, 2005 05:28PM

James Adams wrote:
> Sorry if this is elementary, I haven't been able
> to find this info in the MySQL manual or from
> various Google searches. Basically I have MySQL
> 4.1.8-nt installed on my Windows XP machine and I
> need to provide a database URL for Hibernate and
> I'm not sure of how I specify this URL. Here are
> the database configuration values which are used
> in creating the URL (from what I can tell):
> host = localhost, or nassau.harborside.local
> (actual name)
> port = 3306
> database name = notebook
> I have tried the following with no success:
> jdbc:mysql:thin:@localhost:3306:notebook
> jdbc:mysql:thin://nassau:3306:notebook
> jdbc:mysql://localhost/notebook
> If someone can direct me to a site which explains
> how to create a database URL from a particular set
> of database configuration values then I'd
> certainly appreciate the help. Thanks in
> advance...


Sure. This is in the JDBC driver docs (probably the place you _haven't_ looked?) at or they also come with your JDBC any case, here's an excerpt:

"Driver Class Name and JDBC URL Format

The name of the class that implements java.sql.Driver in MySQL Connector/J is 'com.mysql.jdbc.Driver'. The '' class name is also usable to remain backwards-compatible with MM.MySQL. You should use this class name when registering the driver, or when otherwise configuring software to use MySQL Connector/J.

The JDBC URL format for MySQL Connector/J is as follows, with items in square brackets ([, ]) being optional:


If the hostname is not specified, it defaults to ''. If the port is not specified, it defaults to '3306', 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:


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 would modify data will have exceptions thrown (the query will never be processed by the MySQL server)."


Mark Matthews
Consulting Member Technical Staff - MySQL Enterprise Tools

Options: ReplyQuote

Written By
January 07, 2005 03:51PM
Re: How do I form my database URL ?
January 07, 2005 05:28PM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.