我正在尝试使用JDBC将此代码作为带有derby数据库的netbeans中的.JSP文件的servlet运行。我的问题并没有超出" stmt.addBatch(查询);"它打印"你好"。我还在库中使用了derby.jar,derbyclient.jar和derbynet.jar。
期待听到别人的意见。
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.*;
import java.io.*;
import javax.sql.*;
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
/* TODO output your page here. You may use following sample code. */
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet Reg</title>");
out.println("</head>");
out.println("<body>");
String name=request.getParameter("name");
String rate=request.getParameter("Rate");
out.println(name);
out.println(rate);
Class.forName("org.apache.derby.jdbc.ClientDriver");
Connection con=DriverManager.getConnection("jdbc:derby://localhost:1527/sample","APP","");
Statement stmt=con.createStatement();
String query="insert into movie values('"+rate+"','" +name+ "')";
stmt.addBatch(query);
out.println("hello");
stmt.close();
con.close();
out.println("</body>");
out.println("</html>");
} catch(Exception e){
e.printStackTrace();
} finally {
out.close();
}
}