<%@ page language=
"java"
contentType=
"text/html; charset=BIG5"
pageEncoding=
"BIG5"
%>
<%
@page
import
=
"java.sql.*"
%>
<!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN"
""
>
<html>
<head>
<meta http-equiv=
"Content-Type"
content=
"text/html; charset=BIG5"
>
<title>checkname</title>
</head>
<body>
<%
String user1 = request.getParameter(
"User"
);
String pass1 = request.getParameter(
"Pass"
);
ResultSet rs1;
Statement stmt1;
PreparedStatement pstmt1;
Connection connAcce1;
String strURL1;
try
{
strURL1 =
"jdbc:odbc:access"
;//access为DSN名称
Class.forName(
"sun.jdbc.odbc.JdbcOdbcDriver"
);
connAcce1 = DriverManager.getConnection(strURL1,
""
,
""
);
stmt1 = connAcce1.createStatement();
rs1 = stmt1.executeQuery(
"SELECT * FROM info"
);
while (rs1.next()) {
if (user1.equals(rs1.getString(2))) {
i = 1;break;} else { i = 0;}}if (i == 0) { pstmt1 = connAcce1.prepareStatement("insert into info(Username,Pass) values(?,?)");pstmt1.setString(1, user1);pstmt1.setString(2, pass1);pstmt1.executeUpdate();session.setAttribute("success", "regist success!");request.getRequestDispatcher("success.jsp").forward(request, response);} else { session.setAttribute("error", "用戶名已存在!請重新輸入");request.getRequestDispatcher("error.jsp").forward(request,response);}
stmt1.close();
connAcce1.close();
}
catch
(Exception ex) {
ex.printStackTrace();
}
%>
</body>
</html>