INSERT查询不是woking

时间:2017-01-05 08:08:19

标签: java postgresql jsp

<body>
<%@ page import ="java.sql.*" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="javax.sql.*" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%    
    String pwd = request.getParameter("pass");
    String email = request.getParameter("email");


        Statement st,stt = null;
        Connection con = null;
        int i=0;


    try {

    Class.forName("org.postgresql.Driver");
    con = DriverManager.getConnection("jdbc:postgresql://hostname","username", "Password");

    stt = con.createStatement();
    st = con.createStatement();


         ResultSet rs;  
         rs = stt.executeQuery("select * from users where email='"+email+"'");  

         if (!rs.next()) {

             ResultSet rss;
                 rss = st.executeQuery("insert into users(email,password) values ('"+email+"','"+pwd+"')");

              if(rss.next()) {  

                 response.sendRedirect("index.jsp");
                 out.print("Registration Successfull!"+"<a href='index.jsp'>Go to Login</a>");

               }else {

                    response.sendRedirect("reg.jsp");
                    out.print("Registration was not Successfull!"+"<a href='reg.jsp'>Go to Registration</a>");
                   }

         }else {

             response.sendRedirect("reg.jsp?error=Email already exsist!");
         } 
       }catch (Exception e) {

           e.printStackTrace();
     }

%>
</body>

1 个答案:

答案 0 :(得分:0)

使用executeUpdate进行插入,更新和更新删除, executeQuery用于选择操作