Setting Up MySQL JDBC Development Environment?
This tutorial shows you how to setup development environment that helps you work with MySQL and JDBC. It also illustrates how to load a sample database into MySQL for practicing in the subsequent tutorials.
To set up the development environment, you need to:
- Download and install JDK if it is not available on your local machine. We will use Java JDK 8u45.
- Download and install NetBeans IDE. You can use any Java IDE such as Eclipse or IntelliJ, which is also fine. We choose NetBeans IDE because it’s easy to install and simple to use. We will use NetBeans IDE version 8.0.2. Oracle provides also provide use NetBeans IDE and JDK in one installation file, so you just need to download one and install both JDK and NetBeans.
- Download and install MySQL Connector/J.
Download and install NetBeans IDE with JDK
To download and install NetBeans IDE with JDK, you follow the steps below:
First, you need to go to Oracle Java download page and click on the NetBeans with JDK download button. It takes few minutes to complete the download.
Second, double-click on the installation file, and go through the process. You just have to click Next button until it completes.
Third, once the installation completes, you can launch it by double click on the NetBeans IDE icon.
Download and install MySQL Connector/J
First, go to the Download Connector/J page on mysql.com website.
Second, select your appropriate platform. We will use Windows platform. You can choose your platform specified in the Select Platform drop-down list.
Third, double-click on installation file to install the MySQL Connector/J. Once the install process completes, you can find the JAR file that you will include into your Java application as the screen below:
Load MySQL JDBC sample database
We will use a sample database named
mysqljdbc
for the sake of demonstration. The following illustrates the database diagram:
There are three tables in the sample database.
- candidates: stores candidate data such as first name, last name, date of birth (dob), phone, and email.
- skills: stores skills of candidates
- candidate_skills: the pivot table links between candidates & skills
You can download the sample database via the following link:
To load the sample database, you can do the following steps:
Click Create a new schema icon in the toolbar.
Enter the name of the schema, mysqljdbc, and click apply button
MySQL Workbench will popup a dialog, to show you the DDL statement to create a new schema, just click Apply button.
Click Finish button to complete the schema creation step.
To load table structure and data, choose mysqljdbc database, right click and choose Set as Default Schema.
From File menu, choose Run SQL Script… menu item.
Browse o the location where you download the sample database file mysqljdbc.sql, select the file and click Open button.
MySQL Workbench will display a dialog as following, just click the Run button to execute the script.
Once script executed successfully, click Close button.
To see the result, click on the mysqljdbc and click Refresh button. You will see all tables are loaded successfully.
In this tutorial, we have shown you how to setup development environment for working with JDBC & MySQL and load the
mysqljdbc
sample database.
0 comments:
Post a Comment