JDBC example with mysql

JDBC example with mysql

ThisĀ is a basic example which describe how to connect mysql using JDBC. In practice very few peopleĀ uses JDBC as there are more advance frameworks like Hiberante, Spring templates, iBatis are available. However, it is advisable to know the basic of JDBC which help to understand more advance frameworks.
This tutorial describes how to use Java JDBC to connect to MySQL and perform select query on emp table. Technologies used in this examples are :

  1. Mysql
  2. Maven
  3. JDK 1.7

In MySQL, Emp table is created which contains three columns id, firstName and lastName. There are 2 emp records are available with Emp table as below.

emp JDBC

Step 1: Add Mysql connector to project classpath.

In this example maven is used as build tool, so add below dependency to the pom.xml file. In case you are not using maven manually add mysql-connector jar to your projects classpath.

Step 2: code snippet to connection with mysql.

Step 3 : Complete example with select Statement.

Step 4: Load and run the program


Leave a Reply

Your email address will not be published. Required fields are marked *