package campiology.
dao;
import [Link].*;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class CustomerDAO {
static Connection currentCon = null;
static ResultSet rs = null;
static PreparedStatement ps=null;
static Statement stmt=null;
static String custEmail, custName, custPhone, custPassword;
static double rating;
//login
public static CustomerBean CustomerLoginController(CustomerBean bean) throws
NoSuchAlgorithmException {
custEmail = [Link]();
custPassword = [Link]();
String searchQuery = "select * from customers where custEmail = '" +
custEmail + "' AND custPassword = '" + custPassword + "'";
[Link]("Your email is " + custEmail);
[Link]("Your password is " + custPassword);
[Link]("Query: " + searchQuery);
try {
currentCon = [Link]();
stmt = [Link]();
rs = [Link](searchQuery);
boolean more = [Link]();
// if user exists set the isValid variable to true
if (more) {
String custEmail = [Link]("custEmail");
[Link]("Welcome " + custEmail);
[Link](custEmail);
[Link](true);
}
// if user does not exist set the isValid variable to false
else if (!more) {
[Link]("Sorry, you are not a registered user! Please
sign up first");
[Link](false);
}
catch (Exception ex) {
[Link]("Log In failed: An Exception has occurred! " + ex);
}
finally {
if (rs != null) {
try {
[Link]();
} catch (Exception e) {
}
rs = null;
}
if (stmt != null) {
try {
[Link]();
} catch (Exception e) {
}
stmt = null;
}
if (currentCon != null) {
try {
[Link]();
} catch (Exception e) {
}
currentCon = null;
}
}
return bean;
}
//add new user (register)
public void add(CustomerBean bean) throws NoSuchAlgorithmException{
custEmail = [Link]();
custName = [Link]();
custPhone = [Link]();
custPassword = [Link]();
try {
currentCon = [Link]();
ps=[Link]("insert into customers
(custEmail,custPassword,custName,custPhone)values(?,?,?,?)");
[Link](1,custEmail);
[Link](2,custPassword);
[Link](3,custName);
[Link](4,custPhone);
[Link]();
[Link]("Your email is " + custEmail);
[Link]("Your password is " + custPassword);
catch (Exception ex) {
[Link]("failed: An Exception has occurred! " + ex);
}
finally {
if (ps != null) {
try {
[Link]();
} catch (Exception e) {
}
ps = null;
}
if (currentCon != null) {
try {
[Link]();
} catch (Exception e) {
}
currentCon = null;
}
}
}
public static CustomerBean getUser(CustomerBean bean) {
custEmail = [Link]();
String searchQuery = "select * from customers where custEmail='" +
custEmail + "'";
try {
currentCon = [Link]();
stmt = [Link]();
rs = [Link](searchQuery);
boolean more = [Link]();
// if user exists set the isValid variable to true
if (more) {
String email = [Link]("custEmail");
[Link](email);
[Link](true);
}
else if (!more) {
[Link]("Sorry");
[Link](false);
}
catch (Exception ex) {
[Link]("Log In failed: An Exception has occurred! " + ex);
}
finally {
if (rs != null) {
try {
[Link]();
} catch (Exception e) {
}
rs = null;
}
if (stmt != null) {
try {
[Link]();
} catch (Exception e) {
}
stmt = null;
}
if (currentCon != null) {
try {
[Link]();
} catch (Exception e) {
}
currentCon = null;
}
}
return bean;
}
}