100% found this document useful (1 vote)
2K views4 pages

Ajp Practical 20

The document describes two Java programs that use JDBC to perform operations on a database table. The first program deletes a record from a table where the student ID is 101. The second program updates the name of a student from "Jack" to "John" where the name is currently "Jack". It then prints the records from the table.

Uploaded by

nstrnsdtn
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
100% found this document useful (1 vote)
2K views4 pages

Ajp Practical 20

The document describes two Java programs that use JDBC to perform operations on a database table. The first program deletes a record from a table where the student ID is 101. The second program updates the name of a student from "Jack" to "John" where the name is currently "Jack". It then prints the records from the table.

Uploaded by

nstrnsdtn
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
You are on page 1/ 4

Name : Ayush Maroti Wadje Roll no. : 76 Practical no.

: 20

2. Write a program to delete a record from a table

Import java.sql.*;
public class Emp
{
public static void main(String[] args){
try{
Connection con = DriverManager.getConnection("jdbc:ucanaccess://D://Employee1.accdb");
Statement s = con.createStatement();
s.execute("Create Table SData (STUD_ID int, STUD_Name varchar(255),BRANCH
varchar(255))");
s.execute("Delete from SData where STUD_ID=101");
s.execute("select * from SData");
ResultSet rs = s.getResultSet();
if (rs != null){
while ( rs.next() ) {
System.out.println("Id of the Student: " + rs.getString(1) );
System.out.println("Name of Student: " + rs.getString(2) );
System.out.println("Branch of Student: " + rs.getString(3) );
System.out.println("********************************************88" );}

s.close();
con.close();}}
catch (Exception err){
System.out.println("ERROR: " +err);
}
}
}

Output
XIII. Exercise

1. Develop a program to update name of a student from Jack to John.

import java.sql.*;
public class Emp
{
public static void main(String[] args){
try{
Connection con =
DriverManager.getConnection("jdbc:ucanaccess://D://Employee1.accdb");
Statement s = con.createStatement();
// s.execute("Create Table SData (STUD_ID int, STUD_Name
varchar(255),BRANCH varchar(255))");
s.execute("Update SData set STUD_NAME = 'john' where STUD_NAME = 'Jack')");
s.execute("select * from SData");
ResultSet rs = s.getResultSet();
if (rs != null){
while ( rs.next() ) {
System.out.println("Id of the Student: " + rs.getString(1) );
System.out.println("Name of Student: " + rs.getString(2) );
System.out.println("Branch of Student: " + rs.getString(3) );
System.out.println("********************************************88"
);}

s.close();
con.close();}}
catch (Exception err){
System.out.println("ERROR: " +err);
}
}
}
2.Develop a program to delete all record for a product whose “price” id” is greater
than 500 and Id is “P1234”

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class PR_AD_20_3


{
public static void main(String[] args){
try{
Connection con = DriverManager.getConnection("jdbc:ucanaccess://D://Database.accdb");
Statement s = con.createStatement();
int flag = s.executeUpdate("Delete from List where P_id>'1234' AND price>500");
System.out.println("Rows Deleted " + flag);
s.execute("select * from List");
ResultSet rs = s.getResultSet();
if (rs != null){
while ( rs.next() ){
System.out.println(" " );
System.out.println("Id of the Product : " + rs.getString(1) );
System.out.println("Price of the Product: " + rs.getString(2) );
System.out.println(" " );}
s.close();
con.close();}}
catch (Exception err){
System.out.println("ERROR: " + err);}}
}

Output

You might also like