<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>
答案 0 :(得分:0)
使用executeUpdate
进行插入,更新和更新删除,
executeQuery
用于选择操作