Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Created by vyas on 10/16/16.
- */
- import java.sql.Connection;
- import java.util.Scanner;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.Statement;
- public class Attendance {
- public static void main(String[] args) {
- Connection con= null;
- Statement stat = null;
- Scanner in = new Scanner(System.in);
- String sql=null;
- String username,password;
- System.out.println("\n\n\t\t\t\tWelcome To Attendance Manager ( Faculty Side )");
- // System.out.println("\n\n\t\t\tEnter UserName for the Oracle Server! ");
- // username=in.next();
- // System.out.println("Enter Password for the Oracle Database ");
- // password=in.next();
- username="cse14059";
- password="cseamrita";
- String path1="oracle.jdbc.driver.OracleDriver";
- String path2="jdbc:oracle:thin:";
- int choice;
- path2=path2.concat(username);
- path2=path2.concat("/");
- path2=path2.concat(password);
- path2=path2.concat("@oracle.amritanet.edu:1521/amrita2016.amritanet.edu");
- try{
- Class.forName(path1);
- con=DriverManager.getConnection(path2);
- stat=con.createStatement();
- sql="create table attendance(name varchar2(20),total integer,attended integer)";
- //sql="drop table attendance";
- stat.execute(sql);
- System.out.println("\n\n\t\tMenu : \n\n\t\t1) Add Subject \n\t\t 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");
- System.out.println("\n\n\t\tEnter a Valid Option to Continue ! : - ( 1 / 2 )");
- choice=in.nextInt();
- String rollno,status,val;
- String subject;
- int total,attended;
- switch(choice){
- case 1: System.out.println("Enter Subject Name");
- subject=in.next();
- sql="insert into attendance values('";
- sql=sql.concat(subject);
- sql=sql.concat("',0,0)");
- System.out.println(sql);
- stat.execute(sql);
- break;
- case 2: ResultSet res =null;
- sql="select * from attendance";
- res = stat.executeQuery(sql);
- boolean records = res.next();
- if(!records){
- System.out.println("No data found");
- }
- else
- {
- do{
- subject=res.getString(1);
- total=res.getInt(2);
- attended=res.getInt(3);
- }while(res.next());
- }
- break;
- case 3: System.out.println("Enter Subject Name to update attendance followed by status ( p / a )");
- subject=in.next();
- status=in.next();
- if(status=="p")
- val="1";
- else val="0";
- sql="update attendance set totalclass=totalclass+1 and attended=attended+";
- sql=sql.concat(val);
- sql=sql.concat(" where subject=");
- sql=sql.concat(subject);
- sql=sql.concat("\"");
- stat.execute(sql);
- break;
- }
- }catch(Exception e){
- e.printStackTrace();
- }
- finally{
- try{
- stat.close();
- con.close();
- }catch(Exception e){e.printStackTrace();}
- }
- }}
Add Comment
Please, Sign In to add comment