-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeleteTest.java
More file actions
71 lines (64 loc) · 1.52 KB
/
Copy pathDeleteTest.java
File metadata and controls
71 lines (64 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package com.intellect.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;
public class DeleteTest {
public static void main(String[] args) {
Scanner sc=null;
String city=null;
Connection con=null;
Statement st=null;
String query=null;
int count=0;
try {
sc=new Scanner(System.in);
if(sc!=null) {
System.out.println("Enter student city(address)");
city=sc.next();
}
city="'"+city+"'";
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "system","oracle");
if(con!=null)
st=con.createStatement();
query="DELETE FROM STUDENT WHERE ADDRS="+city;
System.out.println(query);
if(st!=null)
count=st.executeUpdate(query);
if(count==0)
System.out.println("no records are found to delete");
else
System.out.println(count+" no.of records are deleted");
}//try
catch(SQLException se) {
se.printStackTrace();
}
catch(Exception e) {
e.printStackTrace();
}
finally {
try {
if(st!=null)
st.close();
}
catch(SQLException se) {
se.printStackTrace();
}
try {
if(con!=null)
con.close();
}
catch(SQLException se) {
se.printStackTrace();
}
try {
if(sc!=null)
sc.close();
}
catch(Exception e) {
e.printStackTrace();
}
}//finally
}//main
}//class