如何解决此代码中的错误?

时间:2018-04-21 06:32:07

标签: jsp

    <%@ page language="java" %>
    <%@page import="java.sql.*"%> <%@ page import ="javax.sql.*, java.util.*" %>
    <% String UserName = request.getParameter("uname");
    String email = request.getParameter("email"); 
String address = request.getParameter("address"); 
String password = request.getParameter("pass"); 
String designation = request.getParameter("designation"); 
String mobileNo = request.getParameter("mobno"); 
String dateofbirth = request.getParameter("dob"); 
String aadharNo = request.getParameter("aadhar");

    try{ 
Class.forName("com.mysql.jdbc.Driver"); Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/rail","root","1234"); 
String query = "insert into users values(?,?,?,?,?,?,?)"; 

PreparedStatement ps = con.prepareStatement(query);



    ps.setString(1,UserName); 
ps.setString(2,email); 
ps.setString(3,address); 
ps.setString(4,password); 
ps.setString(5,designation); 
ps.setInt(6,Integer.parseInt(mobileNo)); 
ps.setString(7,aadharNo); 
ps.setString(8,dateofbirth);
int result = ps.executeUpdate();

    if(result == 1){ 
response.sendRedirect("loginf.html"); 
} 
else{ 
response.sendRedirect("index.html"); 
} 
System.out.print("You are successfully registered...");
}
catch(ClassNotFoundException e){ 
e.printStackTrace(); 
} 
}catch(SQLException e){ e.printStackTrace();        } 
out.close();





    %>

what is to be done to remove the errors in this jsp code?

1 个答案:

答案 0 :(得分:1)

中删除最后的}
catch(ClassNotFoundException e){ 
e.printStackTrace(); 
} 
}

当你以尝试结束时,所以永远不会达到 SQLException 的代码