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. Show 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. LicensingPlease refer to the README and LICENSE files, available in this repository, and the Legal Notices in the MySQL Connector/J documentation for further details. Getting the Latest ReleaseMySQL 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 InstallMySQL Connector/J can be installed from pre-compiled packages that can be downloaded from the MySQL Connector/J download page. Installing MySQL Connector/J only requires obtaining the corresponding JAR file from the downloaded bundle or installer and including it in the application's CLASSPATH. According to how you use MySQL Connector/J, you may also need to install the following third-party libraries on your system for it to work:
As a Maven DependencyAlternatively, MySQL 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: <dependency> <groupId>com.mysql</groupId> <artifactId>mysql-connector-j</artifactId> <version>8.0.32</version> </dependency> MySQL Connector/J's own Project Object Model (POM) file specifies a transitive dependency to Protocol Buffers (protobuf-java) since it is required for using X DevAPI. However, if you do not use the X DevAPI features, you may also want to add a dependency exclusion to avoid linking the unneeded sub-library. For example: <dependency> <groupId>com.mysql</groupId> <artifactId>mysql-connector-j</artifactId> <version>8.0.32</version> <exclusions> <exclusion> <groupId>com.google.protobuf</groupId> <artifactId>protobuf-java</artifactId> </exclusion> </exclusions> </dependency> Build From SourceThis driver can also be complied and installed from the source available in this repository. Please refer to the MySQL Connector/J documentation for detailed instructions on how to do it. GitHub RepositoryThis repository contains the MySQL Connector/J source code as per the latest release. No changes are made in this repository between releases. ContributingThere are a few ways to contribute to the MySQL Connector/J code. Please refer to the contributing guidelines for additional information. Akhirnya setelah saya kebingungan membaca manual instalasi MySQL-Connector/J saya menemukan satu buku yang menunjukkan bagaimana instalasi Connector/J dilakukan, buku tersebut berjudul “MySQL and Java Developer’s Guide“. Ternyata setelah saya mencobanya ternyata berhasil dan berakhirlah rasa penasaran saya. Pada tulisan ini saya akan tunjukkan bagaimana instalasi Connector/J (pada tulisan ini saya menggunakan MySQL-Connector/J 5.1) pada Windows platform. Mendapatkan MySQL-Connector/JBila Anda belum mendapatkan MySQL-Connector/J, Anda dapat men-downlolad pada link-link dibawah ini:
Instalasi Connector/JBila Anda sudah mendapatkan MySQL-Connector/J, ekstrak terlebih dahulu. Lalu Anda cari file JAR yang bernama mysql-connector-java-5.1.6-bin, file tersebut yang akan kita copy-kan. Ternyata tidak terlalu sulit untuk melakukan instalasi Connector/J, kita hanya meng-copy file JAR yang bernama mysql-connector-java-5.1.6-bin. Anda buka terlebih dahulu Windows Explorer, lalu cari direktori Java Anda berada (pada komputer saya direktori tersebut berada pada C:\Program Files\Java\), setelah itu ikuti langkah-langkah berikut:
Bila sudah nanti library tersebut akan tersedia untuk aplikasi yang akan mengeksekusinya dalam Java Virtual Machine. Menguji Instalasi MySQL-Connector/JLalu Anda buat file java dengan nama Test, lalu tulis kode berikut ini:
// NamaProgram: Test.java
// Deskripsi: Menguji koneksi MySQL-Connector/J
public class Test
{
public static void main(String args[])
{
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
System.out.println("Berhasil");
}
catch(Exception E)
{
System.out.println("JDBC driver error");
}
} // end of method main
} // end of class Test
Lalu Anda compile file java tadi (saya anggap Anda sudah mengerti cara meng-compile-nya) dan jalankan. Bila berhasil maka program tadi yang sudah dibuat akan menampilkan pesan “Berhasil”, itu berati MySQL-Connector Anda sudah terpasang dengan benar. PenutupBegitulah instalasi MySQL-Connector dilakukan, bila Anda masih bingung dengan langkah-langkahnya, Anda dapat bertanya pada saya untuk penjelasan lebih lanjut. LangkahLangkah-langkah untuk berinteraksi dengan database server dengan menggunakan JDBC adalah sebagai berikut :. Mengimpor package java.sql.. Memanggil Driver JDBC.. Membangun Koneksi.. Membuat Statement.. Melakukan Query.. Memproses Hasil.. Menutup Koneksi.. Penanganan Error.. Bagaimana langkahLangkah-langkah menghubungkan Java dengan MySQL:. Impor package java.sql.* ;. Daftarkan driver atau pilih driver yang akan digunakan;. Buat Sebuah Koneksi;. Exsekusi sebuah Query;. Tutup koneksi dan selesai.. Apa yang dibutuhkan agar Java dapat terkoneksi dengan database tersebut jelaskan?Agar Java dapat berkomunikasi ke database MySQL dibutuhkan sebuah driver yaitu JDBC(Java Database Conectivity).
Apa itu SQLException?SQLException adalah komponen untuk menangani kesalahan-kesalahan yang mungkin terjadi saat pengolahan database.
|