<%@page import="java.awt.Window"%>
<%@page import="beans.Account"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
String account = new String(request.getParameter("account").getBytes("ISO-8859-1"),"UTF-8");
String password = new String(request.getParameter("password").getBytes("ISO-8859-1"),"UTF-8");
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; //加載JDBC驅動
String dbURL = "jdbc:sqlserver://localhost:1433; DatabaseName=化妝品管理系統"; //連接服務器和數據庫sample
String userName = "sa"; //默認用戶名
String userPwd = "123456"; //密碼
Connection conn;
Class.forName(driverName);
conn = DriverManager.getConnection(dbURL, userName, userPwd);
Statement stat = conn.createStatement();
String sql =
"select * FROM Login WHERE account ='"+ account +"'";
ResultSet result = stat.executeQuery(sql);
Account acount = new Account();
while (result.next()){
acount.setPassword(result.getString("password").trim());
acount.setName(result.getString("name").trim());
acount.setId(result.getString("id").trim());
}
out.println(acount.getId());
if(Integer.parseInt(password.trim())==Integer.parseInt(acount.getPassword().trim())){
out.print(acount.getId().trim()=="員工");
//{
// out.print("員工");
// }
// else if(acount.getId()=="管理員"){
// out.print("管理員");
// response.sendRedirect("customManage.jsp");
// }
// else if(acount.getId()=="顧客"){
// out.print("顧客");
// response.sendRedirect("index.jsp");
// }
}
else
out.print("WRONG");
result.close();
stat.close();
%>
sql中字符串相等用=
在java中用equals