MySQL Connection Help

Listed below are connection examples for MySQL:

MySQL Connector/J Driver


DRIVER CLASS: com.mysql.jdbc.Driver

DRIVER LOCATION: Simply provide the location of the jar file containing the MySQL JDBC Drivers. These drivers can be obtained from MySQL. See the MySQL web site for more information.

Example: mysql-connector-java-3.1.11-bin.jar

JDBC URL FORMAT: jdbc:mysql://<host>:<port>/<database_name>

The default port for MySQL is 3306. Usually, if the default port is being used by the database server, the :<port> value of the JDBC url can be omitted.

ADDITIONAL JDBC CONNECTION PROPERTIES

Additional connection properties can be appended to the JDBC URL. The format to add connection properties is the following:

jdbc:mysql://<host>:<port>/<database_name>?property1=value1&property2=value2&property3=value3

Here are examples of connection properties for the MySQL Connector/J driver. Consult your driver documentation for more examples of connection properties.

connectTimeout (Timeout for socket connect (in milliseconds), with 0 being no timeout. Only works on JDK-1.4 or newer. Defaults to 0.)

socketTimeout (Timeout on network socket operations (0, the default means no timeout).)

autoReconnect (Should the driver try to re-establish stale and/or dead connections.)

Examples:

jdbc:mysql://neptune.acme.com:3306/test

jdbc:mysql://127.0.0.1:3306/test

jdbc:mysql://localhost:3306/mysql?connectTimeout=0&socketTimeout=0&autoReconnect=true