├── .classpath ├── .project ├── .settings └── org.eclipse.jdt.core.prefs ├── bin ├── Start.class └── com │ └── student │ └── management │ ├── CP.class │ ├── Student.class │ └── StudentDao.class └── src ├── Start.java └── com └── student └── management ├── CP.java ├── Student.java └── StudentDao.java /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | StudentManagement 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=16 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=16 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning 13 | org.eclipse.jdt.core.compiler.release=enabled 14 | org.eclipse.jdt.core.compiler.source=16 15 | -------------------------------------------------------------------------------- /bin/Start.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ayusrv/StudentManagement/09b465c8c6a0f1ca325b284634f76d31e8df66a7/bin/Start.class -------------------------------------------------------------------------------- /bin/com/student/management/CP.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ayusrv/StudentManagement/09b465c8c6a0f1ca325b284634f76d31e8df66a7/bin/com/student/management/CP.class -------------------------------------------------------------------------------- /bin/com/student/management/Student.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ayusrv/StudentManagement/09b465c8c6a0f1ca325b284634f76d31e8df66a7/bin/com/student/management/Student.class -------------------------------------------------------------------------------- /bin/com/student/management/StudentDao.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ayusrv/StudentManagement/09b465c8c6a0f1ca325b284634f76d31e8df66a7/bin/com/student/management/StudentDao.class -------------------------------------------------------------------------------- /src/Start.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | 5 | import com.student.management.Student; 6 | import com.student.management.StudentDao; 7 | 8 | public class Start { 9 | 10 | public static void main(String[] args) throws NumberFormatException, IOException { 11 | // TODO Auto-generated method stub 12 | System.out.println("Hello"); 13 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 14 | while(true) { 15 | System.out.println("PRESS 1 to add student"); 16 | System.out.println("PRESS 2 to Delete student"); 17 | System.out.println("PRESS 3 to Display student"); 18 | System.out.println("PRESS 4 to Exit App"); 19 | int c = Integer.parseInt(br.readLine()); 20 | if(c==1) { 21 | //add student.. 22 | System.out.println("Enter user name: "); 23 | String name=br.readLine(); 24 | System.out.println("Enter user phone: "); 25 | String phone=br.readLine(); 26 | System.out.println("Enter user city: "); 27 | String city=br.readLine(); 28 | 29 | //create student object to store student 30 | Student st = new Student(name,phone,city); 31 | boolean answer = StudentDao.insertStudentToDB(st); 32 | if(answer) { 33 | System.out.println("Student is added successfully..."); 34 | } 35 | else { 36 | System.out.println("Something went wrong try again.."); 37 | } 38 | System.out.println(st); 39 | } 40 | else if(c==2) { 41 | //delete student 42 | System.out.println("Enter Student Id to delete: "); 43 | int userId = Integer.parseInt(br.readLine()); 44 | boolean answer = StudentDao.deleteStudent(userId); 45 | if(answer) { 46 | System.out.println("Student is deleted successfully..."); 47 | } 48 | else { 49 | System.out.println("Something went wrong try again.."); 50 | } 51 | } 52 | else if(c==3) { 53 | //display student 54 | StudentDao.showAll(); 55 | } 56 | else if(c==4) { 57 | //exit 58 | break; 59 | } 60 | else { 61 | System.out.println("Please choose the correct option"); 62 | } 63 | } 64 | System.out.println("Thankyou for using my Application..."); 65 | System.out.println("See you soon...bye bye"); 66 | 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/com/student/management/CP.java: -------------------------------------------------------------------------------- 1 | package com.student.management; 2 | 3 | import java.sql.Connection; 4 | import java.sql.DriverManager; 5 | 6 | public class CP { 7 | 8 | static Connection con; 9 | 10 | public static Connection createC() { 11 | 12 | 13 | try { 14 | //Load the driver 15 | Class.forName("com.mysql.cj.jdbc.Driver"); 16 | 17 | //create the connection... 18 | String user="root"; 19 | String password = "Ayushsri@1305"; 20 | String url = "jdbc:mysql://localhost:3306/student_management"; 21 | con=DriverManager.getConnection(url,user,password); 22 | } 23 | catch(Exception e) { 24 | e.printStackTrace(); 25 | } 26 | return con; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/com/student/management/Student.java: -------------------------------------------------------------------------------- 1 | package com.student.management; 2 | 3 | public class Student { 4 | private int studentId; 5 | private String studentName; 6 | private String studentPhone; 7 | private String studentCity; 8 | public Student(int studentId, String studentName, String studentPhone, String studentCity) { 9 | super(); 10 | this.studentId = studentId; 11 | this.studentName = studentName; 12 | this.studentPhone = studentPhone; 13 | this.studentCity = studentCity; 14 | } 15 | public Student(String studentName, String studentPhone, String studentCity) { 16 | super(); 17 | this.studentName = studentName; 18 | this.studentPhone = studentPhone; 19 | this.studentCity = studentCity; 20 | } 21 | public Student() { 22 | super(); 23 | // TODO Auto-generated constructor stub 24 | } 25 | public int getStudentId() { 26 | return studentId; 27 | } 28 | public void setStudentId(int studentId) { 29 | this.studentId = studentId; 30 | } 31 | public String getStudentName() { 32 | return studentName; 33 | } 34 | public void setStudentName(String studentName) { 35 | this.studentName = studentName; 36 | } 37 | public String getStudentPhone() { 38 | return studentPhone; 39 | } 40 | public void setStudentPhone(String studentPhone) { 41 | this.studentPhone = studentPhone; 42 | } 43 | public String getStudentCity() { 44 | return studentCity; 45 | } 46 | public void setStudentCity(String studentCity) { 47 | this.studentCity = studentCity; 48 | } 49 | @Override 50 | public String toString() { 51 | return "Student [studentId=" + studentId + ", studentName=" + studentName + ", studentPhone=" + studentPhone 52 | + ", studentCity=" + studentCity + "]"; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/com/student/management/StudentDao.java: -------------------------------------------------------------------------------- 1 | package com.student.management; 2 | 3 | import java.sql.Connection; 4 | import java.sql.PreparedStatement; 5 | import java.sql.ResultSet; 6 | import java.sql.Statement; 7 | 8 | public class StudentDao { 9 | public static boolean insertStudentToDB(Student st) { 10 | boolean f = false; 11 | //jdbc code 12 | try { 13 | Connection con = CP.createC(); 14 | String q="insert into students(sname,sphone,scity) values(?,?,?)"; 15 | //prepared statement 16 | PreparedStatement pstmt = con.prepareStatement(q); 17 | //set the values of parameter 18 | pstmt.setString(1, st.getStudentName()); 19 | pstmt.setString(2, st.getStudentPhone()); 20 | pstmt.setString(3, st.getStudentCity()); 21 | 22 | //execute 23 | pstmt.executeUpdate(); 24 | f=true; 25 | }catch(Exception e) { 26 | e.printStackTrace(); 27 | } 28 | return f; 29 | } 30 | 31 | public static boolean deleteStudent(int userId) { 32 | 33 | boolean f = false; 34 | //jdbc code 35 | try { 36 | Connection con = CP.createC(); 37 | String q="delete from students where sid=?"; 38 | //prepared statement 39 | PreparedStatement pstmt = con.prepareStatement(q); 40 | //set the values of parameter 41 | pstmt.setInt(1, userId); 42 | //execute 43 | pstmt.executeUpdate(); 44 | f=true; 45 | }catch(Exception e) { 46 | e.printStackTrace(); 47 | } 48 | return f; 49 | } 50 | 51 | public static void showAll() { 52 | try { 53 | Connection con = CP.createC(); 54 | String q="select * from students"; 55 | Statement stmt = con.createStatement(); 56 | ResultSet set = stmt.executeQuery(q); 57 | 58 | while(set.next()) { 59 | int id=set.getInt(1); 60 | String name=set.getString(2); 61 | String phone=set.getString(3); 62 | String city=set.getString("scity"); 63 | 64 | System.out.println("ID: "+id); 65 | System.out.println("Name: "+name); 66 | System.out.println("Phone: "+phone); 67 | System.out.println("City: "+city); 68 | System.out.println("--------------"); 69 | } 70 | }catch(Exception e) { 71 | e.printStackTrace(); 72 | } 73 | } 74 | } 75 | --------------------------------------------------------------------------------