How to connect a java application with mysql database in its simplest form.
The simplest solution I can think of is to use maven or similar package, and build tool to import the dependency i.e., mysql-jdbc-connector.jar
- Sprint Tool Suite IDE: Version: 3.7.1.RELEASE
- Java 8
- MySQL Server: 5.5.44
- (Optional) MySQL Workbench: 6.2
MySQL database setup
Run below script to create a schema (database), and table.
In Eclipse, create a maven project and add MainApp.java class, and update the pom.xml file as below.
Create a java class as below with main method which uses mysql jdbc connector to communicate with MySQL database.
Right click the MainApp.java and run as Java Application to get below output: