【发布时间】:2013-11-21 10:55:44
【问题描述】:
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) {
}
}
}
我在“loans”表中保留了一个字段 loan_id 作为必须自动递增的主键。然后我编写了上面的查询,用于在表中插入一条新记录。我从另一个 JSP 获取这些值。但是我的表没有得到更新。请解决这个问题..
【问题讨论】:
-
IN 第二个 catch 块添加一个 exception.printStackTrace() 那么它将给出什么......写下你的问题或让它更清楚......
-
它没有抛出任何异常
标签: java sqlexception jdbc-odbc