MySQL Tutorials - Herong's Tutorial Examples - v4.46, by Herong Yang
Connection URL Tests on Older MySQL Connector/J
Describes the connection URL format test program and result with older MySQL Connector/J releases.
As a comparison, I kept my Connection URL Test program for older MySQL Connector/J releases as below:
/* MySqlConnectionUrl.java * Copyright (c) 2005 HerongYang.com. All Rights Reserved. */ import java.sql.*; public class MySqlConnectionUrl { public static void main(String [] args) { Connection con = null; try { Class.forName("com.mysql.jdbc.Driver") ; System.out.println("MySQL JDBC driver loaded ok."); con = DriverManager.getConnection( "jdbc:mysql://localhost:3306/test?" + "user=root&password=TopSecret"); System.out.println("Connected with host:port/database."); con.close(); con = DriverManager.getConnection( "jdbc:mysql://:3306/test?" + "user=root&password=TopSecret"); System.out.println("Connected with default host."); con.close(); con = DriverManager.getConnection( "jdbc:mysql://localhost/test?" + "user=root&password=TopSecret"); System.out.println("Connected with default port."); con.close(); con = DriverManager.getConnection( "jdbc:mysql://localhost:3306/?" + "user=root&password=TopSecret"); System.out.println("Connected with no database."); con.close(); con = DriverManager.getConnection( "jdbc:mysql:///?" + "user=root&password=TopSecret"); System.out.println("Connected with properties only."); con.close(); } catch (Exception e) { System.err.println("Exception: "+e.getMessage()); } } }
Here is the output of running the above program on my MySQL 5.7.10 server with default settings and mysql-connector-java-5.1.38-bin.jar. The warning message tells me that the connection was made with SSL, but the server's certificate was not verified.
herong> java -cp .;\local\lib\mysql-connector-java-5.1.38-bin.jar MySqlConnectionUrl MySQL JDBC driver loaded ok. WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. Connected with host:port/database. WARN... Connected with default host. WARN... Connected with default port. WARN... Connected with no database. WARN... Connected with properties only.
As a comparison, here is the output on MySQL 5.0 server:
herong> java -cp .;\local\lib\mysql-connector-java-5.1.38-bin.jar MySqlConnectionUrl MySQL JDBC driver loaded ok. Connected with host:port/database. Connected with default host. Connected with default port. Connected with no database. Connected with properties only.
Table of Contents
MySQL Introduction and Installation
Introduction of MySQL Programs
Perl Programs and MySQL Servers
►Java Programs and MySQL Servers
MySQL Connector/J - Download and Installation
Loading JDBC Driver Class - com.mysql.cj.jdbc.Driver
►Connection URL Tests on Older MySQL Connector/J
Creating Connections with DataSource Class
Getting Driver and Server Information
Creating Tables with AUTO_INCREMENT Columns
Character Strings and Bit Strings
Table Column Types for Different Types of Values
Using DDL to Create Tables and Indexes
Using DML to Insert, Update and Delete Records
Using SELECT to Query Database
Window Functions for Statistical Analysis
Use Index for Better Performance
Transaction Management and Isolation Levels
Defining and Calling Stored Procedures
Variables, Loops and Cursors Used in Stored Procedures
System, User-Defined and Stored Procedure Variables
Storage Engines in MySQL Server
InnoDB Storage Engine - Primary and Secondary Indexes
Performance Tuning and Optimization
Installing MySQL Server on Linux