Connecting to MySQL With Java Program
MySQL is an open-source relational database management system (RDBMS). It's name is a combination of "My", the name of co-founder Michael Widenius' daughter, and "SQL", the abbreviation for Structured Query Language.
The MySQL development project has made its source code available under the terms of the GNU General Public License, as well as under a variety of proprietary agreements. MySQL was owned and sponsored by a single for-profit firm, the Swedish company MySQL AB, now owned by Oracle Corporation.
1) A machine with Ubuntu 14.04 LTS operating system
2) MySQL Server installed (How to install MySQL in Ubuntu)
3) mysql-connector-java.jar file
Connecting to MySQL with Java Example
The following steps to connect to MySQL Server with Java Client.
Steps to follow
Step 1 - Enter into MySQL command line inteface(CLI). Open a terminal (CTRL + ALT + T) and type the following command.
Step 2 - Create a new database. Here 'userdb' is the new database name.
Step 3 - Use 'userdb' database for creating tables.
Step 4 - Create a new table. Here 'user' is a new table name.
Step 5 - Add mysql-connector-java.jar to your java project build path. You can find this jar file in /usr/share/java/ folder. If you didn't find, please follow the steps here
Step 6 - Write a Java program for connecting to MySQL database server. Below JdbcConnection.java program inserts the values in user table.
You can check it in MySQL CLI, whether the values are inserted or not.
Please share this blog post and follow me for latest updates on
Previous Post Next Post