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 Application Program

Source Code on eclipse

Output  see on eclipse

run As Java Application

Connection successful

 

 

(Visited 59 times, 1 visits today)

Leave a Reply

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


CAPTCHA Image
Reload Image