-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentRepository.java
More file actions
75 lines (55 loc) · 2.42 KB
/
StudentRepository.java
File metadata and controls
75 lines (55 loc) · 2.42 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
72
73
74
75
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package com.finlogic.step.repository;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
*
* @author ajay
*/
public class StudentRepository {
String url = "jdbc:MYSQL://localhost:3306/steplogindata";
String user = "root";
String password = "MYSQL80";
public ResultSet ViewAllStudents() throws SQLException {
Connection con = DriverManager.getConnection(url, user, password);
PreparedStatement stmt = con.prepareStatement("select * from studentsdata ;");
ResultSet rs = stmt.executeQuery();
return rs;
}
public int InsertStudent(String name, String email, String address, String city, String state) throws SQLException {
Connection con = DriverManager.getConnection(url, user, password);
PreparedStatement stmt = con.prepareStatement("insert into studentsdata(name,email,address,city,state) values(?,?,?,?,?) ;");
stmt.setString(1, name);
stmt.setString(2, email);
stmt.setString(3, address);
stmt.setString(4, city);
stmt.setString(5, state);
int status = stmt.executeUpdate();
return status;
}
public int DeleteStudent(int id) throws SQLException {
Connection con = DriverManager.getConnection(url, user, password);
PreparedStatement stmt = con.prepareStatement("delete from studentsdata where id = ? ;");
stmt.setInt(1, id);
int status = stmt.executeUpdate();
return status;
}
public int EditStudent(int id,String name, String email, String address, String city, String state ) throws SQLException {
Connection con = DriverManager.getConnection(url, user, password);
PreparedStatement stmt = con.prepareStatement("update studentsdata set name=?,email=?,address=?,city=?,state=? where id=? ;");
stmt.setString(1, name);
stmt.setString(2, email);
stmt.setString(3, address);
stmt.setString(4, city);
stmt.setString(5, state);
stmt.setInt(6, id);
int status = stmt.executeUpdate();
return status;
}
}