0% found this document useful (0 votes)
16 views2 pages

Unit4 JDBC Program

The Java program demonstrates the use of JDBC to connect to a MySQL database named 'bank'. It includes operations to delete a customer record and retrieve all customer records, displaying their details. Error handling is implemented to catch SQL exceptions during database operations.

Uploaded by

saoryayadav3
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views2 pages

Unit4 JDBC Program

The Java program demonstrates the use of JDBC to connect to a MySQL database named 'bank'. It includes operations to delete a customer record and retrieve all customer records, displaying their details. Error handling is implemented to catch SQL exceptions during database operations.

Uploaded by

saoryayadav3
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

import [Link].

*;

import [Link];

import [Link];

import [Link];

public class Demo_JDBC {

public static void main(String[] args) {

// TODO Auto-generated method stub

String url = "jdbc:mysql://localhost:3306/bank";

String user = "root";

String password = "newpassword";

try {

Connection con=[Link](url,user,password);

[Link]("Connection created with bank Database");

Statement stmt=[Link]();

/*String strInsert="insert into customer values(3,'Mohan',22,3000)";

int val=[Link](strInsert);

if(val>0) {

[Link]("Value Inserted in Database");

}*/

/*String strUpdate="update customer set bal=4000, name='Sumit Ku' where id=2";

int val=[Link](strUpdate);

if(val>0) {

[Link]("Value Updated in Database");

}*/

String strDel=" delete from customer where id=3";

int val=[Link](strDel);

if(val>0) {
[Link]("Value Deleted from Database");

String strSelect="select * from customer";

ResultSet rs=[Link](strSelect);

while([Link]()) {

int id =[Link]("id");

String name=[Link]("Name");

int age=[Link]("age");

int bal=[Link](4);

[Link](id + " " + name +" "+age +" "+bal);

catch(SQLException e) {

[Link]([Link]());

You might also like