Sir i need a online quiz program coding using java servlet, jdbc odbc connection with ms. access. If possible send that source code to me. Thank you.
<%-- This code working perfectly --%> <%@page import="java.sql.*"%> <%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
String st[]=new String[1000];
for(int i=0;i }
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/oxfords","oxford", "oxford123");
Statement stmt=connection.createStatement();
ResultSet rs=stmt.executeQuery("Select * from quiz");
String ans="";
while(rs.next()){
ans+=rs.getString(7)+" ";
}
int count=0;
int wrong=0;
int nu=0;
String answers[]=ans.split(" ");
for(int i=0;i }
out.println("Your "+count+" answers are correct");
out.println("Your "+wrong+" answers are wrong");
out.println("Your "+nu+" Not answere");
%>
}
}else{
nu++;
}
Create table test(ques,op1,op2,op3,op4,ans) and answers(id,ans). Then try the following code:
1)form.jsp:
<%@page import="java.sql.*"%> <html> <form method="post" action="result.jsp"> <table> <% Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/register","root";, "root"); Statement st=connection.createStatement(); ResultSet rs=st.executeQuery("Select * from test"); int i=1; while(rs.next()){ %> <tr><td><%=i%></td><td><%=rs.getString("ques")%></td><td><input type="radio" value="<%=rs.getString("op1")%>" name="radio<%=i%>"/><%=rs.getString("op1")%></td><td><input type="radio" value="<%=rs.getString("op2")%>" name="radio<%=i%>"/><%=rs.getString("op2")%></td><td><input type="radio" value="<%=rs.getString("op3")%>" name="radio<%=i%>"/><%=rs.getString("op3")%></td><td><input type="radio" value="<%=rs.getString("op4")%>" name="radio<%=i%>"/><%=rs.getString("op4")%></td></tr> <% i++; } %> <tr><td><input type="submit" value="submit"></td></tr> </table> </form> </html>
2)result.jsp:
<%@page import="java.sql.*"%> <% String st[]=new String[10]; for(int i=0;i<st.length;i++){ int j=i+1; st[i]=request.getParameter("radio"+j); System.out.println(st[i]); } Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/register","root";, "root"); Statement stmt=connection.createStatement(); ResultSet rs=stmt.executeQuery("Select ans from answers"); String ans=""; while(rs.next()){ ans+=rs.getString("ans")+" "; } int count=0; String answers[]=ans.split(" "); for(int i=0;i<answers.length;i++){ if(st[i].equals(answers[i])){ count++; } } out.println("Your "+count+" answers are correct"); %>
For more information, visit the following link:
http://www.roseindia.net/jsp/online-quiz-application-jsp.shtml
Thanks
Thanks 4 d code.can u pls tel me how can we modify it to get random questions 4m mysql??
The source code above works fine but whenever an answer radio button is not selected it throws an Null pointer exception. How to resolve this problem.Please help. Thanks in advance
can anyone explain how to Create table test(ques,op1,op2,op3,op4,ans) and answers(id,ans)
then to execute the prog????????
hello sir. I already follow the code above But Can I know how to get the number of incorrect answers if the user click the wrong answer.
Thank you
Ads