-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdateTest.java
More file actions
50 lines (45 loc) · 1.48 KB
/
Copy pathUpdateTest.java
File metadata and controls
50 lines (45 loc) · 1.48 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
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 UpdateTest {
public static void main(String[] args) {
int no = 0;
String newName = null, newAddrs = null;
float newAvg = 0.0f;
int count = 0;
try {
Scanner sc = new Scanner(System.in);
if (sc != null) {
System.out.println("Enter exisiting student number::");
no = sc.nextInt();
System.out.println("Enter new Name for student ::");
newName = sc.next();
System.out.println("Enter new Address for student ::");
newAddrs = sc.next();
System.out.println("Enter new avg for student ::");
newAvg = sc.nextFloat();
}
newName = "'" + newName + "'";
newAddrs = "'" + newAddrs + "'";
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "system", "oracle");
Statement st = con.createStatement();
String query = "UPDATE STUDENT SET NAME=" + newName + ",ADDRS=" + newAddrs + ",AVG=" + newAvg
+ " WHERE SNO=" + no;
System.out.println(query);
count = st.executeUpdate(query);
if (count == 0)
System.out.println("No Record is updated");
else
System.out.println(count + " no.of record(s) are updated");
st.close();
con.close();
} catch (SQLException se) {
se.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}// main
}// class