Guest User

Format ada

a guest
Oct 18th, 2016
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.39 KB | None | 0 0
  1. /**
  2. * Created by vyas on 10/16/16.
  3. */
  4. import java.sql.Connection;
  5. import java.util.Scanner;
  6. import java.sql.DriverManager;
  7. import java.sql.ResultSet;
  8. import java.sql.Statement;
  9. public class Attendance {
  10.  
  11. public static void main(String[] args) {
  12.  
  13. Connection con= null;
  14. Statement stat = null;
  15. Scanner in = new Scanner(System.in);
  16. String sql=null;
  17. String username,password;
  18. System.out.println("\n\n\t\t\t\tWelcome To Attendance Manager ( Faculty Side )");
  19. username="cse14059";
  20. password="cseamrita";
  21. String path1="oracle.jdbc.driver.OracleDriver";
  22. String path2="jdbc:oracle:thin:";
  23. int choice;
  24. path2=path2.concat(username);
  25. path2=path2.concat("/");
  26. path2=path2.concat(password);
  27. path2=path2.concat("@oracle.amritanet.edu:1521/amrita2016.amritanet.edu");
  28. try{
  29. Class.forName(path1);
  30. con=DriverManager.getConnection(path2);
  31. stat=con.createStatement();
  32. //sql="create table attendance(name varchar2(20),total integer,attended integer)";
  33. //sql="drop table attendance";
  34. // stat.execute(sql);
  35. while(true) {
  36.  
  37. //System.out.flush();
  38. System.out.println("\n\n\t\tMenu : \n\n\t\t1) Add Subject \n\t\t2) Show Attendance in All Subjects!\n\t\t 3) Update Attendance !\n\t\t3) Show All Subjects With Attendance Below 75% \n\t\t 4) Remove Subject");
  39. System.out.println("\n\n\t\tEnter a Valid Option to Continue ! : - ( 1 / 2 )");
  40. choice = in.nextInt();
  41.  
  42. String rollno, status, val;
  43. String subject;
  44. int total, attended;
  45. switch (choice) {
  46. case 1:
  47. System.out.println("Enter Subject Name");
  48. subject = in.next();
  49. sql = "insert into attendance values('";
  50. sql = sql.concat(subject);
  51. sql = sql.concat("',0,0)");
  52. System.out.println(sql);
  53. stat.execute(sql);
  54. break;
  55. case 2:
  56. ResultSet res = null;
  57. sql = "select * from attendance";
  58. res = stat.executeQuery(sql);
  59. boolean records = res.next();
  60. if (!records) {
  61. System.out.println("No data found");
  62. } else {
  63. do {
  64. subject = res.getString(1);
  65. total = res.getInt(2);
  66. attended = res.getInt(3);
  67. System.out.println("Subject : "+subject);
  68. System.out.println("Total Classes Conducted : "+total);
  69. System.out.println("Total Classes Attended : "+attended);
  70. System.out.println();
  71. } while (res.next());
  72. }
  73. break;
  74. case 3:
  75. System.out.println("Enter Subject Name to update attendance");
  76. subject = in.next();
  77. System.out.println("Enter status ( p / a )");
  78. status = in.next();
  79. if (status.equals("p"))
  80. val = "1";
  81. else val = "0";
  82. sql = "update attendance set total=total+1, attended=attended+"+val+" where name='"+subject+"'";
  83. stat.executeUpdate(sql);
  84.  
  85. break;
  86. case 4:
  87. System.out.println("Enter Subject Name to remove attendance record :");
  88. subject = in.next();
  89. sql = "delete from attendance where name = '"+subject+"'";
  90. stat.executeUpdate(sql);
  91.  
  92. break;
  93.  
  94. }
  95. }
  96. }catch(Exception e){
  97. e.printStackTrace();
  98. }
  99. finally{
  100. try{
  101. stat.close();
  102. con.close();
  103. }catch(Exception e){e.printStackTrace();}
  104. }
  105. }}
Add Comment
Please, Sign In to add comment