-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentUpdate.java
More file actions
52 lines (40 loc) · 1.33 KB
/
StudentUpdate.java
File metadata and controls
52 lines (40 loc) · 1.33 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
package com.test.multipleRecord;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;
public class StudentUpdate {
private void getStudentDetails(String name, String city, String salary) throws SQLException {
Connection connection = null;
PreparedStatement pre = null;
try {
ConnectionTest connectionTest = new ConnectionTest();
connection = connectionTest.getConnectionTest();
pre = connection.prepareStatement("INSERT INTO student (name, city, salary) VALUES (?,?,?)");
pre.setString(1, name);
pre.setString(2, city);
pre.setString(3, salary);
int in = pre.executeUpdate();
System.out.println("Insertion completed " + in);
} catch (Exception e) {
System.out.println(e);
e.printStackTrace();
} finally {
connection.close();
pre.close();
}
}
public static void main(String[] args) throws SQLException {
for (int i = 0; i<= 2; i++) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the name");
String name = scanner.next();
System.out.println("Enter the city");
String city = scanner.next();
System.out.println("Enter the salary");
String salary = scanner.next();
StudentUpdate studentUpdate = new StudentUpdate();
studentUpdate.getStudentDetails(name, city, salary);
}
}
}