<%@ page import= "java.sql.*"
import= "java.util.*"%>
<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/user","root","");
Statement st = con.createStatement();
String name = request.getParameter("name");
String username = request.getParameter("user");
String pass = request.getParameter("pas");
String cpass = request.getParameter("cpas");
String sql2 = "select * from user where user='"+username+"';";
ResultSet rs = st.executeQuery(sql2);
if(rs.next())
{
response.sendRedirect("index.html?err=Username already taken");
}
else
{
String sql = "insert into user values('"+name+"', '"+username+"','"+pass+"',"+cpass+");";
st.executeUpdate(sql);
response.sendRedirect("blank.html");
}
%>
答案 0 :(得分:-1)
的Class.forName( “com.mysql.jdbc.Driver”)的newInstance(); Connection con = DriverManager.getConnection(“jdbc:mysql:// localhost:3306 / user”,“root”,“”); Statement st = con.createStatement();
String name = request.getParameter("name");
String username = request.getParameter("user");
String pass = request.getParameter("pas");
String cpass = request.getParameter("cpas");
String sql2 = "select * from user where user='"+username+"';";
ResultSet rs = st.executeQuery(sql2);
if(rs != null && rs.next())
{
response.sendRedirect("index.html?err=Username already taken");
}
else
{
String sql = "insert into user values('"+name+"', '"+username+"','"+pass+"',"+cpass+");";
st.executeUpdate(sql);
response.sendRedirect("blank.html");
}