Eclipse Java Example to connect to the mysql database


 Before creating a java program first we create databse and table in mysql database program.

First  open mysql software program.
https://www.mysql.com/downloads/

Now open MYSQL CommandLine Client

In COmmandLine CLient follow the steps  for create database and table and queries.

 

step-1 :  Enter Passwrod : root

step-2 :  mysql >create database mydatabase;
query Ok, 1 row effected (0.05 sec)

step-3 :  mysql >use mydatabase;
Database changed

step-4 :  mysql >create table mytable(NO INT,NAME VARCHAR(25));

query Ok, 0 rows effected (0.36 sec)
step-5 :  mysql >describe mytable;

 

 

1 .  insert query in MYSQL

step-6 :  mysql >insert into mytable(NO,NAME)values(1,’Apple’);
query Ok, 1 row effected (0.03 sec)

step-7 :  mysql >insert into mytable(NO,NAME)values(2,’Mango’);
query Ok, 1 row effected (0.03 sec)

step-8 :  mysql >insert into mytable(NO,NAME)values(3,’Banana’);
query Ok, 1 row effected (0.03 sec)

 

2 .  select query in MYSQL

step-9 :  mysql >select * from mytable;
3 rows in set (0.00 sec)

 

3 .  update query in MYSQL

step-10 :  mysql >update mytable set NAME=’Banana’ where NO=3;
query Ok, 1 row effected (0.03 sec)

step-11 :  mysql >select * from mytable;
3 rows in set (0.00 sec)

 

4 . delete query in MYSQL

step-12 :  mysql >delete from mytable where NO=2;
query Ok, 1 row effected (0.05 sec)

step-13 :  mysql >exit


Java Program Connect With MySQL Database in Eclipse Framework

Eclipse Java Example to connect to the mysql database

First open eclipse IDE

file -new project

Right click on project – Build path – Add External Archives

add jar file  mysql-connector-java-5.1.45-bin

Right click on project – New – Class – Jdbc1

now write down this  below program

Output  of Java Program in Eclipse

Right Click on program code window

Run As – Java Application

 

(Visited 419 times, 4 visits today)

Leave a Reply

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


CAPTCHA Image
Reload Image