插入值表分支后,我想创建一个新表。值来自 jsp 页面。值已成功插入,但未创建表,它不检查 if 语句,我只有一个空白页。谢谢你。
package Servlets;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet(name = "Decidetest", urlPatterns = {"/Decidetest"})
public class Decidetest extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
Connection con;
Statement s;
String branch=request.getParameter("branch");
String semester=request.getParameter("semester");
String course=request.getParameter("course");
String name=request.getParameter("tname");
String time=request.getParameter("duration");
String number=request.getParameter("number");
String type=request.getParameter("r1");
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:online_testing");
s=con.createStatement();
String sql="insert into tests(branch,sem,course,testname,duration,noofque) values('"+branch+"','"+semester+"','"+course+"','"+name+"','"+time+"','"+number+"')";
s.executeUpdate(sql);
String sql3="CREATE TABLE "+name+"(option1 varchar(255)),option2 varchar(255),option3 varchar(255),option4 varchar(255),answer varchar(255)) ";
s.executeUpdate(sql3);
s.close();
con.close();
if(type.equals("make"))
{
response.sendRedirect("preparetest.jsp");
}
else
{
response.sendRedirect("selectbank.jsp");
}
} catch (SQLException ex) {
Logger.getLogger(Decidetest.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(Decidetest.class.getName()).log(Level.SEVERE, null, ex);
} finally {
out.close();
}
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}