Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static final String JDBC_DRIVER="com.mysql.jdbc.Driver";
- static final String DB_URL="jdbc:mysql://localhost/aishwarya";
- static final String USER="Aishwarya";
- static final String PASS="Aishwaryakadam06";
- public static void main(String[] args) throws IOException, SQLException {
- Scanner scan = new Scanner(System.in);
- Connection con=null;
- Statement st=null;
- try {
- Class.forName("com.mysql.jdbc.Driver");
- System.out.println("Connection to database...");
- con= (Connection) DriverManager.getConnection(DB_URL, USER, PASS);
- System.out.println("Creating Statement...");
- st= (Statement) con.createStatement();
- String sql;
- System.out.println("Press enter to start the test: ");
- String Question_id1 = scan.nextLine();
- sql = "SELECT * FROM quiz1 limit 2";
- ResultSet rs=st.executeQuery(sql);
- while(rs.next())
- {
- int Question_id=rs.getInt("Question_id");
- System.out.print(""+Question_id);
- String Question_text=rs.getString("Question_text");
- System.out.println(" "+Question_text);
- String A=rs.getString("A");
- System.out.println("A: "+A);
- String B=rs.getString("B");
- System.out.println("B: "+B);
- String C=rs.getString("C");
- System.out.println("C: "+C);
- String D=rs.getString("D");
- System.out.println("D: "+D);
- System.out.println("Submit Answer ");
- String CorrectAnswer1 = scan.nextLine();
- int count= 0;
- String CorrectAnswer = rs.getString("CorrectAnswer") ;
- for (int i=0; i< 1; i++) {
- if (CorrectAnswer.equals(CorrectAnswer1))
- {
- System.out.println("Correct ");
- count++;
- }
- else
- {
- System.out.println("Wrong!!" );
- count--;
- }
- System.out.println("Marks: " +count);
- System.out.println(" ");
- } //for
- } //while
- System.out.println(" **Correct Answers** ");
- System.out.println(" ");
- ResultSet rs1=st.executeQuery(sql);
- while(rs1.next())
- {
- for(int i=0;i<1;i++)
- {
- int Question_id=rs1.getInt("Question_id");
- System.out.print(" " +Question_id );
- } //for 2
- sql = "SELECT * FROM quiz1";
- String CorrectAnswer2=rs1.getString("CorrectAnswer");
- System.out.println(" Correct Answer is: " +CorrectAnswer2);
- System.out.println(" ");
- } //while2
- rs1.close();
- rs.close();
- st.close();
- con.close();
- } //try
- }
- }
- catch(SQLException se2)
- {
- se2.printStackTrace();
- }
- try //connection
- {
- if(con!=null)
- con.close();
- }
- catch(SQLException se)
- {
- se.printStackTrace();
- }
- } //psvm
- } //main class
- `
Add Comment
Please, Sign In to add comment