public class grantLoan extends HttpServlet {
private static final long serialVersionUID = 1L;
Connection con;
Statement st;
public grantLoan() {
super();
}
public Connection getCon()
{
try
{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/microfinance", "root", "");
}
catch (Exception e) {
e.printStackTrace();
}
return con;
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
try
{
String category = request.getParameter("category");
System.out.println(category);
String addr = request.getParameter("addres");
System.out.println(addr);
Integer income = request.getIntHeader("sal");
System.out.println(income);
Integer amount = request.getIntHeader("amount");
System.out.println(amount);
String tenure = request.getParameter("tenure");
System.out.println(tenure);
String assets = request.getParameter("surity");
System.out.println(assets);
String type_of_payment = request.getParameter("paymentType");
System.out.println(type_of_payment);
HttpSession session = request.getSession();
int accno = (Integer)session.getAttribute("acno");
con=getCon();
st = con.createStatement();
PreparedStatement pst = (PreparedStatement) con.prepareStatement("insert into loans(Account_no,category,Present_address,Required_Amount,Duration,Assets,income,Payment_type) values('?','?','?','?','?','?','?','?')");
pst.setInt(2, accno);
pst.setString(3, category);
pst.setString(4, addr);
pst.setInt(5, amount);
pst.setString(6, tenure);
pst.setString(7, assets);
pst.setInt(8, income);
pst.setString(9, type_of_payment);
int i= pst.executeUpdate();
if(i==1)
{
System.out.println("loans table updated successfully");
response.sendRedirect("UserHome.jsp");
}
}
catch(Exception exception) {
}
}
}
I have kept a field loan_id in the table 'loans' as a primary key which has to be automatically incremented. And then I wrote the above query for the insertion of a new record into the table. I am getting these values from another JSP .But my table is not getting updated. plz do solve this..