You are on page 1of 7

M-UNIVERSITY ON CLOUD

ANNEXURE - II
SOURCE CODE
package com.database; import java.sql.*; public class DBConnection { Connection con=null; public Connection getConnection() { try{ Class.forName("com.mysql.jdbc.Driver"); con=DriverManager.getConnection("jdbc:mysql://localhost:3306/muniversitydb","root","root); } catch(Exception e) { e.printStackTrace(); } return con; } }

1 HITECH COLLEGE OF ENGINEERING AND TECHNOLOGY

M-UNIVERSITY ON CLOUD FOR LOGIN VALIDATION METHOD FOR ADMIN, PROFESSOR, STUDENT

@WebMethod public String validation(UserLoginFile obj_userlogin) { String responsexml="<root>"; System.out.println("The Select Category is : "+obj_userlogin.getDesig()); System.out.println("The username received is : "+obj_userlogin.getUsername()); System.out.println("The password received is : "+obj_userlogin.getPassword()); try { responsexml+="<verify>"; rs= stmt.executeQuery("select name,hallticketno,designation,branch,studyyear from studenttb where hallticketno='"+obj_userlogin.getUsername()+"' and password='"+obj_userlogin.getPassword()+"'"); if(rs.next()) { System.out.println("valid user"); /* * Making response as "adminlogin" if the user is admin and "studentlogin" if the user is student */ String v_checkuser=rs.getString(3); responsexml+="<loginname>"+rs.getString(3)+"</loginname>"; responsexml+="</verify>"; if(v_checkuser.equals("student")) { 2 HITECH COLLEGE OF ENGINEERING AND TECHNOLOGY

M-UNIVERSITY ON CLOUD responsexml+="<studentdetails>"; responsexml+="<uname>"+rs.getString(1)+"</uname>"; responsexml+="<username>"+rs.getString(2)+"</username>"; responsexml+="<ubranch>"+rs.getString(4)+"</ubranch>"; responsexml+="<studyyear>"+rs.getString(5)+"</studyyear>"; responsexml+="</studentdetails>"; } } else { // Making response as "loginfail" if unauthorized User responsexml+="<loginname>loginfail</loginname>"; responsexml+="</verify>"; } responsexml+="</root>"; } catch (Exception e) { System.out.println("There is an Exception"); e.printStackTrace(); responsexml+="<loginname>serverproblem</loginname>"; responsexml+="</verify>"; responsexml+="</root>"; } // sending response back to Flex mobile 3 HITECH COLLEGE OF ENGINEERING AND TECHNOLOGY

M-UNIVERSITY ON CLOUD return responsexml; } REGISTRATION METHOD FOR STUDENT @WebMethod public String userRegistration(UserRegistrationFile obj_register_file) { String response=null; System.out.println("the employee register details are "+obj_register_file.getR_username()+" "+obj_register_file.getR_studyyear()+" " ); try { // Checking Whether the username is already exists or not rs= stmt.executeQuery("select name,password from studenttb where hallticketno='"+obj_register_file.getR_username()+"'"); if(rs.next()) { System.out.println("userexists"); // Making response as "userexists" if the username is already exists response="userexists"; } else { // Inserting Registration Values into Registration Table int insert_val=stmt.executeUpdate("INSERT INTO studenttb values('"+ obj_register_file.getR_name()+"','"+obj_register_file.getR_username()+"','"+obj_register_file.getR_password()+"','"+ 4 HITECH COLLEGE OF ENGINEERING AND TECHNOLOGY "+obj_register_file.getR_name() + "

"+obj_register_file.getR_emailid()+" "+obj_register_file.getR_branch()+" "+obj_register_file.getR_college()+"

M-UNIVERSITY ON CLOUD obj_register_file.getR_emailid()+"','"+obj_register_file.getR_branch()+"','"+obj_register_file.getR_studyyear()+"','"+o bj_register_file.getR_college()+"','student')"); System.out.println("student Details Stored Successfully"); // Making response as "registrationsucess" response="studentregistrationsucess"; } }

catch(Exception ex) { System.out.println(" There is an Exception"); ex.printStackTrace(); // Making response as "registrationfail" response="registrationfail"; }

// sending response back to Flex mobile return response; } PROFESSOR CREATING QUESTION PAPERS @WebMethod public String preparingQuestions(PreparingQuestionsFile obj_preparequestion) { String response=null; System.out.println(" The received data are : " + obj_preparequestion.getV_question() +" "+obj_preparequestion.getV_solution()+" "+obj_preparequestion.getV_option_A()+" 5 HITECH COLLEGE OF ENGINEERING AND TECHNOLOGY

M-UNIVERSITY ON CLOUD "+obj_preparequestion.getV_option_B()+" "+obj_preparequestion.getV_option_D()); try { // stmt=con.createStatement(); // checking the count of question present for each subject, if >5 then already questions are given rs=stmt.executeQuery("select qcount from examsubjecttb where subjectid='"+obj_preparequestion.getV_testpaperid()+"'"); if(rs.next()) { String countcheck=rs.getString(1); int countchecki=Integer.parseInt(countcheck); if(countchecki<5) { //---- inserting questions int insert_info=stmt.executeUpdate("insert into exampapertb(testpaperid,questionname,solution,optiona,optionb,optionc,optiond) values('"+obj_preparequestion.getV_testpaperid()+"','"+obj_preparequestion.getV_question()+"','"+obj_preparequestio n.getV_solution()+"','"+obj_preparequestion.getV_option_A()+"','"+obj_preparequestion.getV_option_B()+"','"+obj_p reparequestion.getV_option_C()+"','"+obj_preparequestion.getV_option_D()+"')"); System.out.println("Question Inserted Sucessfully into table"); //-----updating count to check the number of questions int update_count=stmt.executeUpdate("update examsubjecttb set qcount=qcount+1 where subjectid='"+obj_preparequestion.getV_testpaperid()+"'"); System.out.println("Question qcount incremented into examsubject table"); response="question inserted sucessfully"; System.out.println(response); 6 HITECH COLLEGE OF ENGINEERING AND TECHNOLOGY "+obj_preparequestion.getV_option_C()+"

M-UNIVERSITY ON CLOUD } else { response="already questions are given"; System.out.println(response); } } else { response="already questions are given"; System.out.println(response); } } catch (Exception e) { System.out.println("There is an Exception"); e.printStackTrace(); response="server connection problem"; System.out.println(response); } return response }

7 HITECH COLLEGE OF ENGINEERING AND TECHNOLOGY

You might also like