Practical No 20
Practical No 20
Practical No 20
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;
try {
Statement s = con.createStatement();
s.execute("CREATE TABLE SData ([STUD JD] int, STUD_Name varchar(255), BRANCH varchar(255))");
if (rs != null) {
while (rs.next()) {
System.out.println("*******************************************");
rs.close();
s.close();
con.close();
}
XIII. Exercise
1. Develop a program to update name of a student from Jack to John.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;
try {
Connection con =
DriverManager.getConnection("jdbc:ucanaccess://C:/Users/admin/OneDrive/Documents/MSBTE.accdb");
Statement s = con.createStatement();
ResultSet rs = s.getResultSet();
if (rs != null) {
while (rs.next()) {
System.out.println("********************************************");
s.close();
con.close();
}
2.Develop a program to delete all record for a product whose "price" id" is greater than 500 and Id is “1234"
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
try {
Connection con =
DriverManager.getConnection("jdbc:ucanaccess://C:/Users/admin/OneDrive/Documents/MSBTE.accdb");
Statement s = con.createStatement();
int flag = s.executeUpdate("DELETE FROM List WHERE P_id = '1234' AND price > 500");
ResultSet rs = s.getResultSet();
if (rs != null) {
while (rs.next()) {
System.out.println(" ");
s.close();
con.close();