Connector/J JDBC Driver Connection URL String

Q

What is the correct format Connector/J JDBC Driver Connection URL string? I am getting exceptions when calling the DriverManager.getConnection(url) method.

✍: FYIcenter.com

A

When you are calling the DriverManager.getConnection(url) method to establish a connection to a MySQL database through the Connector/J JDBC driver, you have to provide the connection URL string as the input in a correct format:

jdbc:mysql://<server>[:<port>][/<database>]
   [?<property>=<value>[&<property>=<value>]...]

Here is the explanation of different parts in the connection URL string:

  • <server> - The value must be the server name, with domain name if needed, where the database service is running. You can also use IP address of the server too.
  • <port> - The value should be the port number where the database server is listening to connection requests. This part is optional. If not specified, the Connector/J driver will use the default value: 3306 for MySQL.
  • <database> - The value should be the MySQL database name that the connection should associated to. If not specified, the connection will not be associated to any database on the MySQL server.
  • <property>=<value>[;...] - This part is optional, except "user" and "password", which are required if you are using MySQL authentication. You can use it to specify a list of property values to change their default values supported by Connector/J JDBC driver.

 

Connector/J JDBC Driver Connection Properties

ShowJdbcDrivers.java - Connector/J JDBC Driver Example

Examples for Connector/J - JDBC Driver for MySQL

⇑⇑ FAQ for Connector/J - JDBC Driver for MySQL

2016-12-04, 1165🔥, 0💬