0

How can I retrieve an entire database in JSP and compare the first record with the first parameter obtained from a HTML form, the second record with the second parameter obtained from the HTML form and so on..??

Here is my code:

MS-ACCESS database:-

database name: question
table name : ques

qno answer
1 A
2 A
3 A

index.html

<html>	
<head>
	<title>RESULT</title>
	<style type="text/css">
		body { margin:10px; font-size:13pt;}
		span { font-size:14pt; color:red; }
		form { margin:30px; }
		h { font-size:19pt; color:red;}
	</style>
</head>
<body>

	<center><h> Quarterly Examination - Question Paper </h></center>
	<form name="form" method="post" action="time.jsp"/>
		1. When did the First World War start? <br/>
			<input type="radio" name="1" value="A"/> 1914 &nbsp&nbsp&nbsp&nbsp
			<input type="radio" name="1" value="B"/> 1915 &nbsp&nbsp&nbsp&nbsp
			<input type="radio" name="1" value="C"/> 1916 &nbsp&nbsp&nbsp&nbsp
			<input type="radio" name="1" value="D"/> 1917 
		<br/><br/>
			
		2. Who was called 'The Fuhrer'? <br/>
			<input type="radio" name="2" value="A"/> Hitler &nbsp&nbsp&nbsp&nbsp
			<input type="radio" name="2" value="B"/> Mussolini &nbsp&nbsp&nbsp&nbsp
			<input type="radio" name="2" value="C"/> Herbert Hoover &nbsp&nbsp&nbsp&nbsp
			<input type="radio" name="2" value="D"/> Frankin Roosevelt
		<br/><br/>
		
		3. Which crown prince's murder triggered the First World War? <br/>
			<input type="radio" name="3" value="A"/> Austria &nbsp&nbsp&nbsp&nbsp
			<input type="radio" name="3" value="B"/> Spain &nbsp&nbsp&nbsp&nbsp
			<input type="radio" name="3" value="C"/> England &nbsp&nbsp&nbsp&nbsp
			<input type="radio" name="3" value="D"/> France
		<br/><br/>
		
		&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp <input type="submit" name="submit" value="Submit">
	</form>			
	
</body>
</html>

time.jsp

<%@page contentType="text/html" import="java.util.*" 	import="java.sql.*"%>
<% 
	String ans1 = request.getParameter("1");
	String ans2 = request.getParameter("2");
	String ans3 = request.getParameter("3");
	
	
	String query = "select * from ques";	
	Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
	Connection c1 =  DriverManager.getConnection("Jdbc:Odbc:question","","");
	Statement state = c1.createStatement(); 
	ResultSet r1 = state.executeQuery(query);
	while(r1.next())
	{
	}
	
	response.getWriter().println("<body><br/><br/><center><h1> Exam Result </h1>");
	response.getWriter().println("Your score is :");
	response.getWriter().println("</center></body>");
%>

I dont know how to compare the values inside the while loop.

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by vijiraghs
0

You are looking at it from wrong point, plus not giving full problem description. From what I seen in your code I assume that you are trying to do examination system.

So what we know is that in database we have set or CORRECT_ANSWERS and we need to check them against a STUDENT_ANSWERS. What they have in common is the structure so they should be easy to compare. So what you need to do is
1. get STUDENT_ANSWERS from submit form
2. get CORRECT_ANSWER from database
3. write method that will compare STUDENT_ANSWER_1 with CORRECT_ANSWER_1 and increment score
4. once comparison done return score value

In your scenario the fastest solution would be use of Collection like array or list and simple looping through one collection, getting element from other collection in same index position and compare them

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.