i am new in jsp and i used this code to insert data into msaccess table i got problem that when i click submit button after filing all required field the page should redirect to quiz.jsp. but it is not happening and noting inserted to the db too.
<%@page language="java" import="java.sql.*" %>
<%
if(request.getParameter("submit")!=null)
{
Connection conn=null;
Statement stmt=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection("jdbc:odbc:biplob");
try{
Statement st = con.createStatement();
String quest = request.getParameter("quest").toString();
String QA = request.getParameter("QA").toString();
String QB = request.getParameter("QB").toString();
String QC = request.getParameter("QC").toString();
String QD = request.getParameter("QD").toString();
String correctAns = request.getParameter("correctAns").toString();
out.println("quest : " + quest);
String qry = "insert into quiz(quest,QA,QB,QC,QD,correctAns)values('"+quest+"','"+QA+"','"+QB+"','"+QC+"','"+QD+"','"+correctAns+"')";
out.println("qry : " + qry);
int val = st.executeUpdate(qry);
if(val>0)
{
response.sendRedirect("quiz.jsp");
}
con.close();
}
catch(SQLException ex){
System.out.println("SQL satatment not found");
}
}
catch(Exception e){
e.printStackTrace();
}
}
%>
pls help me wih this .. where is wrong in this code .