sganesh
Journeyman
Hi,
i am creating online Quiz application using JSP and MySQl ,Apache 6 in Netbeans IDE.
i am able to successfully display first question from database,and can say the answer is correct or not,,but i can't implement the program further ,in such way that when clicking next button ,new question gets displayed and score calculated there after!,
index.jsp
----------------------------------------------------------------------------------------------------
<%--
Document : start
Created on : Nov 16, 2008, 2:58:18 PM
Author : Ganesh
--%>
<%@ page import="java.sql.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"*www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<% String ans=" ";
Connection conn = null;
Statement st = null;
ResultSet rs = null;
int i=1;
String s,g;
int count=0;
try {
//Class.forName("com.mysql.jdbc.Driver").newInstance();
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn =
DriverManager.getConnection("jdbc:mysql://localhost:3306/MyNewDatabase","root","");
st = conn.createStatement();
//for(i=1;i<=2;i++)
// {
rs = st.executeQuery("select * from quiz where n="+i);
while(rs.next()) {
%>
<form name="form1">
Question:
<h3> <%= rs.getString("quest")%></h3>
1: <%= rs.getString("a") %> <input type="radio" name="a" value= "a" />
2: <%= rs.getString("b") %> <input type="radio" name="a" value="b" />
3:<%= rs.getString("c") %> <input type="radio" name="a" value="c" />
4: <%= rs.getString("d") %> <input type="radio" name="a" value="d" />
<input type="submit" value="OK">
</form>
<% g=request.getParameter("a");
%>
<% ans= rs.getString("ans");
if(g.equals(ans)){
count++;
out.println("Correct");}
else
out.println("false");
%>
}
<%
}}
// }
catch (Exception ex) {
ex.printStackTrace();
%>
<%
} finally {
if (rs != null) rs.close();
if (st != null) st.close();
if (conn != null) conn.close();
}
out.println("Score="+count);
%>
</html>
------------------------------------------------------------------------------------------------------
contents of database
mySql-->select * from quiz;
quest a b c d e ans
What is capital of india Chennai Mumbai Delhi bangalore c 1
What is capital of tamil nadu Chennai madurai trichy coim a 2
--------------------------------------------------------------------------------------------
i need Some ideas to build this project !!!
i am creating online Quiz application using JSP and MySQl ,Apache 6 in Netbeans IDE.
i am able to successfully display first question from database,and can say the answer is correct or not,,but i can't implement the program further ,in such way that when clicking next button ,new question gets displayed and score calculated there after!,
index.jsp
----------------------------------------------------------------------------------------------------
<%--
Document : start
Created on : Nov 16, 2008, 2:58:18 PM
Author : Ganesh
--%>
<%@ page import="java.sql.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"*www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<% String ans=" ";
Connection conn = null;
Statement st = null;
ResultSet rs = null;
int i=1;
String s,g;
int count=0;
try {
//Class.forName("com.mysql.jdbc.Driver").newInstance();
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn =
DriverManager.getConnection("jdbc:mysql://localhost:3306/MyNewDatabase","root","");
st = conn.createStatement();
//for(i=1;i<=2;i++)
// {
rs = st.executeQuery("select * from quiz where n="+i);
while(rs.next()) {
%>
<form name="form1">
Question:
<h3> <%= rs.getString("quest")%></h3>
1: <%= rs.getString("a") %> <input type="radio" name="a" value= "a" />
2: <%= rs.getString("b") %> <input type="radio" name="a" value="b" />
3:<%= rs.getString("c") %> <input type="radio" name="a" value="c" />
4: <%= rs.getString("d") %> <input type="radio" name="a" value="d" />
<input type="submit" value="OK">
</form>
<% g=request.getParameter("a");
%>
<% ans= rs.getString("ans");
if(g.equals(ans)){
count++;
out.println("Correct");}
else
out.println("false");
%>
}
<%
}}
// }
catch (Exception ex) {
ex.printStackTrace();
%>
<%
} finally {
if (rs != null) rs.close();
if (st != null) st.close();
if (conn != null) conn.close();
}
out.println("Score="+count);
%>
</html>
------------------------------------------------------------------------------------------------------
contents of database
mySql-->select * from quiz;
quest a b c d e ans
What is capital of india Chennai Mumbai Delhi bangalore c 1
What is capital of tamil nadu Chennai madurai trichy coim a 2
--------------------------------------------------------------------------------------------
i need Some ideas to build this project !!!