レジスターjspページからデータベースswingmailからDealer_Registerテーブルに挿入しようとしていますが、値が挿入されていません。プログラムで例外が発生していないか教えてください。理由を教えてください
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package testing;
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
* @author Admin
*/
public class regdbservlet extends HttpServlet {
/* private static String algorithm = "DESede";
private static Key key = null;
private static Cipher cipher = null;
private static byte[] encrypt(String input)throws Exception {
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] inputBytes = input.getBytes();
return cipher.doFinal(inputBytes);
}
*/
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse res)
throws ServletException, IOException {
/* key = KeyGenerator.getInstance(algorithm).generateKey();
cipher = Cipher.getInstance(algorithm);
response.setContentType("text/html;charset=UTF-8");*/
PrintWriter out = res.getWriter();
String firstname=request.getParameter("firstname");
String surname=request.getParameter("surname");
String email=request.getParameter("email");
String zipcode=request.getParameter("zipcode");
String userId=request.getParameter("userId");
String dealer_password=request.getParameter("dealer_password");
String town=request.getParameter("town");
String country=request.getParameter("country");
//String input = dealer_password;
//byte[] encryptionBytes = encrypt(input);
//String passw=new String(encryptionBytes);
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=swingmail";
String user = "sa";
String pwd = "sa";
Connection con=null;
// Statement st=null;
//ResultSet rs=null;
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con = DriverManager.getConnection(url,user,pwd);
//String sql = "INSERT INTO memory VALUES ('" + surname + "','" + firstname + "'," + userId + ","+ zipcode +",'"+ email +"','"+ dealer_password +"','"+ town +"','"+ country +"')" ;
String sql = "insert into Dealer_Register values (?,?,?,?,?,?,?,?)";
PreparedStatement ps =con.prepareStatement(sql);
ps.setString(1, surname);
ps.setString(2, firstname);
ps.setString(3, userId);
ps.setString(4, zipcode);
ps.setString(5, email);
ps.setString(6, dealer_password);
ps.setString(7, town);
ps.setString(8, country);
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet regdbservlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet regdbservlet at " + request.getContextPath () + "</h1>");
out.println("</body>");
out.println("</html>");
}
catch(Exception cnfe){
cnfe.printStackTrace();
}
finally {
out.close();
}
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Returns a short description of the servlet.
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}