MySQL Stored Procedure Programming: Building High-Performance Web Applications in MySQL (2006) by Guy Harrison, Steven Feuerstein MySQL Crash Course (2005) by Ben Forta A Guide to MySQL (Available Titles Skills Assessment Manager (SAM) - Office 2010) (2005) by Philip J. Recommended Windows Download: MySQL Connector/J is the official JDBC driver for MySQL. MySQL Connector/J 8.0 is compatible with all MySQL versions starting with MySQL 5.6. Additionally, MySQL Connector/J 8.0 supports the new X DevAPI for development with MySQL Server 8.0. Online Documentation: MySQL Connector/J Installation Instructions. To download the latest version of the JDBC driver for MySQL called Connector/J. MySQL Connector/J comes into 2 major versions: 5.1 and 8.0. The latest version 8.0 supports JDBC 4.2 and JDK 8 or higher.
MySQL provides connectivity for client applications developed in the Java programming language with MySQL Connector/J, a driver that implements the Java Database Connectivity (JDBC) API and also MySQL X DevAPI.
MySQL Connector/J 8.0 is a JDBC Type 4 driver that is compatible with the JDBC 4.2 specification. The Type 4 designation means that the driver is a pure Java implementation of the MySQL protocol and does not rely on the MySQL client libraries.
The driver also contains an implementation of MySQL X DevAPI, an application programming interface for working with MySQL as a Document Store through CRUD-based, NoSQL operations.
For more information, please visit the official MySQL Connector/J documentation.
Licensing
Please refer to the README and LICENSE files, available in this repository, and the Legal Notices in the Connector/J documentation for further details.
Getting the Latest Release
MySQL Connector/J is free for usage under the terms of the specified licensing and it runs on any operating system that is able to run a Java Virtual Machine.
Download and Install
MySQL Connector/J can be installed from pre-compiled packages that can be downloaded from the Connector/J download page. Installing Connector/J only requires obtaining the corresponding JAR file from the downloaded bundle or installer and including it in the application's CLASSPATH.
As a Maven Dependency
Alternatively, Connector/J can be obtained automatically via Maven's dependency management by adding the following configuration in the application's Project Object Model (POM) file:
Build From Source
This driver can also be complied and installed from the source available in this repository. Please refer to the Connector/J documentation for detailed instructions on how to do it.
GitHub Repository
This repository contains the MySQL Connector/J source code as per the latest release. No changes are made in this repository between releases.
Contributing
There are a few ways to contribute to the Connector/J code. Please refer to the contributing guidelines for additional information.
Additional Resources
- MySQL Connector/J Developer Guide.
- MySQL Connector/J X DevAPI Reference.
- MySQL Connector/J, JDBC and Java forum.
#connectors
channel in MySQL Community Slack. (Sign-up required if you do not have an Oracle account.)- @MySQL on Twitter.
- MySQL and Java Mailing Lists.
- InsideMySQL.com Connectors Blog.
- MySQL Bugs Database.
For more information about this and other MySQL products, please visit MySQL Contact & Questions.
- Details
- Written by Nam Ha Minh
- Last Updated on 07 March 2020 | Print Email
1. Download JDBC driver for MySQL
2. No need to load MySQL driver class explicitly
3. Understand the getConnection() method of DriverManager class
4. Java code example connects to MySQL database
1. Download JDBC driver for MySQL
First, in order to have Java program working with MySQL, we need a JDBC driver for MySQL. Browse this URL:http://dev.mysql.com/downloads/connector/j/to download the latest version of the JDBC driver for MySQL called Connector/J. MySQL Connector/J comes into 2 major versions: 5.1 and 8.0. The latest version 8.0 supports JDBC 4.2 and JDK 8 or higher.Click the Download button next to Platform Independent (Architecture Independent), ZIP Archive to download a zip archive. Extract the ZIPfile to a desired location on your computer.Mysql Connector Java 8.0 11 Jar Download For Windows 10
. Copy this file into your project and make it available in your program’s classpath. You can use newer version of JDBC driver for MySQL.If your Java project based on Maven, you just need to declare the following dependency in the pom.xml file:2. No need to load MySQL driver class explicitly
The Connector/J version 8.0 library comes with a JDBC driver class: com.mysql.cj.jdbc.Driver. Before Java 6, we have to load the driver explicitly by this statement:Class.forName('com.mysql.cj.jdbc.Driver');
However that statement is no longer needed, thanks to new update in JDBC 4.0 comes from Java 6. As long as you put the MySQL JDBC driver JAR file file into your program’s classpath, the driver manager can find and load the driver.3. Understand the getConnection() method of DriverManager class
It’s quite easy to make a connection to a database server in general, as well as to a MySQL server in particular. Just using the method getConnection()of the class DriverManager which is available in the packageDownload Mysql-connector-java-8.0.11
java.sql.There are three different signatures of the method getConnection()which we can use:- static Connection getConnection(String url)
- static Connection getConnection(String url, Properties info)
- static Connection getConnection(String url, String user, String password)
- host: host name or IP address of the MySQL server.
- port: port number of the server, default is 3306.
- database: name of the database on the server.
- propertyName1=propertyValue1: a key=value pair for an additional property which will be sent to the server. For example, to send a username and password, write: ?user=root&password=secret
4. Java code example connect to MySQL database
The following example program makes three connections to three MySQL database in three different ways:NOTES: You should close the database connection in the finally clause like this:And since Java 1.7, you can use the try-with-resource syntax that closes the connection automatically, for example:Type the following command to compile the example program:javac MySQLConnectExample.java
Suppose the Connect/J library is placed in the same directory as the MySQLConnectExample.java file. Type the following command to run:java -cp mysql-connector-java-5.1.21-bin.jar;. MySQLConnectExample
And here is the result when running the example program:
That means the program has successfully connected to the MySQL database server.
For visual howto, watch this video:
JDBC API References:
Related JDBC Tutorials:
About the Author:
Nam Ha Minh is certified Java programmer (SCJP and SCWCD). He started programming with Java in the time of Java 1.4 and has been falling in love with Java since then. Make friend with him on Facebook and watch his Java videos you YouTube.[Example program] | 1 kB |