├── .vscode ├── launch.json └── settings.json ├── Database.java ├── Management.java ├── Student.java └── Student_Management.jar /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "java", 9 | "name": "Launch Current File", 10 | "request": "launch", 11 | "mainClass": "${file}" 12 | }, 13 | { 14 | "type": "java", 15 | "name": "Launch Mananagement", 16 | "request": "launch", 17 | "mainClass": "Mananagement", 18 | "projectName": "Student_Management_70eb7b40" 19 | } 20 | ] 21 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "java.project.referencedLibraries": [ 3 | "lib/**/*.jar", 4 | "c:\\Users\\Ankur\\Documents\\mysql-connector-java-8.0.23\\mysql-connector-java-8.0.23\\mysql-connector-java-8.0.23.jar" 5 | ] 6 | } -------------------------------------------------------------------------------- /Database.java: -------------------------------------------------------------------------------- 1 | import java.sql.*; 2 | public class Database{ 3 | Connection conn; 4 | public static String insertStatement="insert into `Students`(id,`name`,`cgpa`,`section`) values(?,?,?,?)"; 5 | public static String printTableStatement="select * from `Students`"; 6 | public static String findByIdStatement="select * from `Students` where `id`=?"; 7 | public static String greaterThanCgpaStatement="select * from `Students` where `cgpa`>=?"; 8 | public static String lessThanCgpaStatement="select * from `Students` where cgpa<=?"; 9 | public static String deleteStatement="delete from `Students` where `id`=?"; 10 | public static String updateStatement="update `Students` set cgpa=? where id=?"; 11 | //Color Codes======================================================================== 12 | final static String ANSI_RESET = "\u001B[0m"; 13 | final static String ANSI_BLACK = "\u001B[30m"; 14 | final static String ANSI_RED = "\u001B[31m"; 15 | final static String ANSI_GREEN = "\u001B[32m"; 16 | final static String ANSI_YELLOW = "\u001B[33m"; 17 | final static String ANSI_BLUE = "\u001B[34m"; 18 | final static String ANSI_PURPLE = "\u001B[35m"; 19 | final static String ANSI_CYAN = "\u001B[36m"; 20 | final static String ANSI_WHITE = "\u001B[37m"; 21 | //=================================================================================== 22 | 23 | Database(String url,String user,String password){ 24 | try{ 25 | this.conn=DriverManager.getConnection(url, user, password); 26 | } 27 | catch (Exception e) { 28 | this.conn=null; 29 | e.printStackTrace(); 30 | } 31 | } 32 | public void closeConnection() throws SQLException{ 33 | this.conn.close(); 34 | System.out.println("\n Database Connection Closed!"); 35 | } 36 | 37 | public boolean insertData(Student std){ 38 | try{ 39 | PreparedStatement statement=this.conn.prepareStatement(insertStatement); 40 | statement.setInt(1, std.id); 41 | statement.setString(2, std.name); 42 | statement.setFloat(3, std.cgpa); 43 | statement.setString(4,std.section); 44 | int rows=statement.executeUpdate(); 45 | return rows>0?true:false; 46 | } 47 | catch(Exception e){ 48 | e.printStackTrace(); 49 | } 50 | return false; 51 | } 52 | 53 | public void findById(int id)throws SQLException{ 54 | PreparedStatement statement=this.conn.prepareStatement(findByIdStatement ,ResultSet.TYPE_SCROLL_INSENSITIVE, 55 | ResultSet.CONCUR_UPDATABLE); 56 | statement.setInt(1,id); 57 | ResultSet res=statement.executeQuery(); 58 | int numberOfRows=0; 59 | while(res.next()){ 60 | numberOfRows++; 61 | } 62 | if(numberOfRows>0){ 63 | res.beforeFirst(); 64 | System.out.println(ANSI_CYAN+"\n =====The Student is======"+ANSI_RESET); 65 | while(res.next()) 66 | { 67 | System.out.println("\n ID : "+res.getString("id")); 68 | System.out.println(" Name : "+res.getString("name")); 69 | System.out.println(" CGPA : "+res.getString("cgpa")); 70 | System.out.println(" Section :"+res.getString("section")); 71 | } 72 | } 73 | else{ 74 | System.out.println(ANSI_RED+"\n =====No Student Found======"+ANSI_RESET); 75 | } 76 | } 77 | 78 | public boolean deleteRecord(int id)throws SQLException{ 79 | PreparedStatement statement=this.conn.prepareStatement(deleteStatement); 80 | statement.setInt(1,id); 81 | return statement.executeUpdate()>0 82 | ?true:false; 83 | } 84 | 85 | public void printDatabase()throws SQLException{ 86 | Statement statement=this.conn.createStatement(); 87 | ResultSet res=statement.executeQuery(printTableStatement); 88 | System.out.println(ANSI_CYAN+"\n =====The Students Are======"+ANSI_RESET); 89 | int counter=0; 90 | while(res.next()) 91 | { 92 | counter++; 93 | System.out.println(ANSI_YELLOW+"\n "+"STUDENT "+counter+ANSI_RESET); 94 | System.out.println("\n ID : "+res.getString("id")); 95 | System.out.println(" Name : "+res.getString("name")); 96 | System.out.println(" CGPA : "+res.getString("cgpa")); 97 | System.out.println(" Section :"+res.getString("section")); 98 | 99 | } 100 | } 101 | 102 | public void getByCgpaCondition(float cgpa,String Cond)throws SQLException{ 103 | String conditionStatement=Cond=="Greater"?greaterThanCgpaStatement:lessThanCgpaStatement; 104 | PreparedStatement statement=this.conn.prepareStatement(conditionStatement,ResultSet.TYPE_SCROLL_INSENSITIVE, 105 | ResultSet.CONCUR_UPDATABLE); 106 | statement.setFloat(1, cgpa); 107 | ResultSet res=statement.executeQuery(); 108 | int numberOfRows=0; 109 | while(res.next()){ 110 | numberOfRows++; 111 | } 112 | if(numberOfRows>0){ 113 | res.beforeFirst(); 114 | System.out.println(ANSI_CYAN+"\n =====The Students are======"+ANSI_RESET); 115 | while(res.next()){ 116 | System.out.println("\n ID : "+res.getString("id")); 117 | System.out.println(" Name : "+res.getString("name")); 118 | System.out.println(" CGPA : "+res.getString("cgpa")); 119 | System.out.println(" Section :"+res.getString("section")); 120 | } 121 | } 122 | else{ 123 | System.out.println(ANSI_RED+"\n =====No Student Found======"+ANSI_RESET); 124 | } 125 | } 126 | 127 | public boolean handleUpdate(int id,float cgpa)throws SQLException{ 128 | PreparedStatement statement=this.conn.prepareStatement(updateStatement); 129 | statement.setFloat(1,cgpa); 130 | statement.setInt(2,id); 131 | return statement.executeUpdate()>0 132 | ?true:false; 133 | } 134 | } -------------------------------------------------------------------------------- /Management.java: -------------------------------------------------------------------------------- 1 | import java.sql.SQLException; 2 | import java.io.*; 3 | class Mananagement{ 4 | //Credentials======================================================================= 5 | public static String MySQLURL = "databaseurl"; 6 | public static String databaseUserName = "databaseusernane"; 7 | public static String databasePassword = "databasepassword"; 8 | //=================================================================================== 9 | 10 | 11 | public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 12 | public static Database database=new Database(MySQLURL,databaseUserName,databasePassword); 13 | 14 | 15 | //Student Datas====================================================================== 16 | public static int id;public static String name,section; 17 | public static float cgpa; 18 | static Student std; 19 | //=================================================================================== 20 | 21 | //Color Codes======================================================================== 22 | final static String ANSI_RESET = "\u001B[0m"; 23 | final static String ANSI_BLACK = "\u001B[30m"; 24 | final static String ANSI_RED = "\u001B[31m"; 25 | final static String ANSI_GREEN = "\u001B[32m"; 26 | final static String ANSI_YELLOW = "\u001B[33m"; 27 | final static String ANSI_BLUE = "\u001B[34m"; 28 | final static String ANSI_PURPLE = "\u001B[35m"; 29 | final static String ANSI_CYAN = "\u001B[36m"; 30 | final static String ANSI_WHITE = "\u001B[37m"; 31 | //=================================================================================== 32 | 33 | 34 | public static void main(String[] args)throws SQLException,IOException{ 35 | if(database.conn!=null){ 36 | System.out.println(ANSI_CYAN+"\n Connection Successfull !"+ANSI_RESET); 37 | int loop=1; 38 | int Case; 39 | while(loop==1){ 40 | System.out.print(ANSI_YELLOW+"\n =====COMMANDS=====\n \n 1 Create Student \n 2 Find by enroll_id \n 3 Delete Record \n 4 Print The Database \n 5 Print Students with CGPA condition \n 6 Update Student CGPA \n\n Option : "+ANSI_RESET); 41 | Case=Integer.parseInt(br.readLine()); 42 | switch(Case){ 43 | case 1:CreateStudent(); 44 | break; 45 | case 2: 46 | System.out.print(ANSI_PURPLE+"\n Enter id : "+ANSI_RESET); 47 | id=Integer.parseInt(br.readLine()); 48 | database.findById(id); 49 | break; 50 | case 3: 51 | System.out.print(ANSI_PURPLE+"\n Enter ID To Delete Student : "+ANSI_RESET); 52 | id=Integer.parseInt(br.readLine()); 53 | boolean res=database.deleteRecord(id); 54 | System.out.println( 55 | res? 56 | ANSI_GREEN+"\n Student Deleted !"+ANSI_RESET: 57 | ANSI_RED+"\n OPPS! Student Not Deleted !"+ANSI_RESET 58 | ); 59 | break; 60 | case 4:database.printDatabase(); 61 | break; 62 | case 5:handleCgpaConditions(); 63 | break; 64 | case 6: 65 | System.out.print(ANSI_PURPLE+"\n Enter ID To Update CGPA : "+ANSI_RESET); 66 | id=Integer.parseInt(br.readLine()); 67 | System.out.print(ANSI_PURPLE+" Enter New CGPA : "+ANSI_RESET); 68 | cgpa=Float.parseFloat(br.readLine()); 69 | res = database.handleUpdate(id,cgpa); 70 | System.out.println( 71 | res? 72 | ANSI_GREEN+"\n Student Updated!"+ANSI_RESET: 73 | ANSI_RED+"\n OPPS! Student Not Updated !"+ANSI_RESET 74 | ); 75 | break; 76 | default: 77 | System.out.println(ANSI_RED+"\n Invalid Choice !"+ANSI_RESET); 78 | } 79 | System.out.print(ANSI_BLUE+"\n Press 1 to continue , else 0 to terminate : "+ANSI_RESET); 80 | loop=Integer.parseInt(br.readLine()); 81 | } 82 | database.closeConnection(); 83 | } 84 | else 85 | System.out.println("Connection Not Succesfull !"); 86 | } 87 | 88 | public static void CreateStudent()throws IOException{ 89 | System.out.println(ANSI_PURPLE+"\n =====Enter Student Credentials====="+ANSI_RESET); 90 | System.out.print(ANSI_PURPLE+"\n Enter id : "+ANSI_RESET); 91 | id=Integer.parseInt(br.readLine()); 92 | System.out.print(ANSI_PURPLE+" Enter Name : "+ANSI_RESET); 93 | name=br.readLine(); 94 | System.out.print(ANSI_PURPLE+" Enter cgpa : "+ANSI_RESET); 95 | cgpa=Float.parseFloat(br.readLine()); 96 | System.out.print(ANSI_PURPLE+" Enter section : "+ANSI_RESET); 97 | section=br.readLine(); 98 | std=new Student(id,name,cgpa,section); 99 | boolean result =database.insertData(std); 100 | System.out.println( 101 | result? 102 | ANSI_GREEN+"\n Student Created !"+ANSI_RESET: 103 | ANSI_RED+"\n Student Not Created !"+ANSI_RESET 104 | ); 105 | } 106 | 107 | public static void handleCgpaConditions()throws IOException, SQLException{ 108 | System.out.println(ANSI_PURPLE+"\n =====Select Cgpa Conditions====="+ANSI_RESET); 109 | System.out.print(ANSI_YELLOW+"\n 1 - Greater Than \n 2 - Less Than \n\n Option : "+ANSI_RESET); 110 | int cgpaCase=Integer.parseInt(br.readLine()); 111 | switch(cgpaCase){ 112 | case 1: 113 | System.out.print(ANSI_PURPLE+"\n Enter CGPA : "+ANSI_RESET); 114 | cgpa=Float.parseFloat(br.readLine()); 115 | database.getByCgpaCondition(cgpa,"Greater");//greater than 116 | break; 117 | case 2: 118 | System.out.print(ANSI_PURPLE+"\n Enter CGPA : "+ANSI_RESET); 119 | cgpa=Float.parseFloat(br.readLine()); 120 | database.getByCgpaCondition(cgpa,"Less");//less than 121 | break; 122 | default: 123 | System.out.println(ANSI_RED+"\n Invalid Choice !"+ANSI_RESET); 124 | } 125 | } 126 | 127 | } 128 | -------------------------------------------------------------------------------- /Student.java: -------------------------------------------------------------------------------- 1 | public class Student{ 2 | int id;String name,section; 3 | float cgpa; 4 | Student(int id,String name,float cgpa,String section) 5 | { 6 | this.id=id; 7 | this.name=name; 8 | this.cgpa=cgpa; 9 | this.section=section; 10 | } 11 | } -------------------------------------------------------------------------------- /Student_Management.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Excalibur79/Student_Management_With_Java/0fe5db80be9143a532ed6464bbf221fad6706204/Student_Management.jar --------------------------------------------------------------------------------