Professional Documents
Culture Documents
dao;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.security.NoSuchAlgorithmException;
import campiology.model.CustomerBean;
import campiology.connection.ConnectionManager;
//login
public static CustomerBean CustomerLoginController(CustomerBean bean) throws
NoSuchAlgorithmException {
custEmail = bean.getCustEmail();
custPassword = bean.getCustPassword();
String searchQuery = "select * from customers where custEmail = '" +
custEmail + "' AND custPassword = '" + custPassword + "'";
try {
currentCon = ConnectionManager.getConnection();
stmt = currentCon.createStatement();
rs = stmt.executeQuery(searchQuery);
boolean more = rs.next();
finally {
if (rs != null) {
try {
rs.close();
} catch (Exception e) {
}
rs = null;
}
if (stmt != null) {
try {
stmt.close();
} catch (Exception e) {
}
stmt = null;
}
if (currentCon != null) {
try {
currentCon.close();
} catch (Exception e) {
}
currentCon = null;
}
}
return bean;
}
custEmail = bean.getCustEmail();
custName = bean.getCustName();
custPhone = bean.getCustPhone();
custPassword = bean.getCustPassword();
try {
currentCon = ConnectionManager.getConnection();
ps=currentCon.prepareStatement("insert into customers
(custEmail,custPassword,custName,custPhone)values(?,?,?,?)");
ps.setString(1,custEmail);
ps.setString(2,custPassword);
ps.setString(3,custName);
ps.setString(4,custPhone);
ps.executeUpdate();
if (currentCon != null) {
try {
currentCon.close();
} catch (Exception e) {
}
currentCon = null;
}
}
}
custEmail = bean.getCustEmail();
try {
currentCon = ConnectionManager.getConnection();
stmt = currentCon.createStatement();
rs = stmt.executeQuery(searchQuery);
boolean more = rs.next();
bean.setCustEmail(email);
bean.setValid(true);
}
else if (!more) {
System.out.println("Sorry");
bean.setValid(false);
}
finally {
if (rs != null) {
try {
rs.close();
} catch (Exception e) {
}
rs = null;
}
if (stmt != null) {
try {
stmt.close();
} catch (Exception e) {
}
stmt = null;
}
if (currentCon != null) {
try {
currentCon.close();
} catch (Exception e) {
}
currentCon = null;
}
}
return bean;
}
}