Sei sulla pagina 1di 3

package WebJ2EE;

import java.sql.*;
public class TechSupportBean {
String url = "jdbc:odbc:Kopi";
private String email;
private String software;
private String os;
private String problem;
private String firstName;
private String lastName;
private String phoneNumber;
private boolean registered;
private String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
private String protocol = "jdbc;odbc;Kopi";
public TechSupportBean() {
try {
Class.forName(driver);
} catch(ClassNotFoundException e) {}
}
public void setEmail(String email) {
this.email = email;}
public void setSoftware(String software) {
this.software = software;}
public void setOs(String os) {
this.os = os;}
public void setProblem(String problem) {
this.problem = problem;}
public void setFirstName(String firstName) {
this.firstName = firstName;}
public void setLastName(String lastName) {
this.lastName = lastName;}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;}
public String getEmail() {
return email;}
public String getSoftware() {
return software;}
public String getOs() {
return os;}
public String getProblem() {
return problem;}
public String getFirstName() {
return firstName;}
public String getLastName() {
return lastName;}
public String getPhoneNumber() {
return phoneNumber;}
public boolean isRegistered() {
return Registered;}
public void registeredSupportRequest() throws SQLException
{
int requestId = 0;
Connection connection = null;
String insertStatmentStr = "INSERT INTO SUPP_REQUEST VALUES(?, ?
, ?, ?, ?)";
String selectCustomerStr = "select customersjava.fname, customer
sjava.lname, customersjava.phone from customersjava where customersjava.email =
?";
String updateStatementStr = "UPDATE SEQ_NO SET NEXT_NO = NEXT_NO
+ 1";
String selectStatementStr = "SELECT NEXT_NO FROM SEQ_NO";
try {
connection = DriverManager.getConnection("jdbc:odbc:supp
ort","sa","");
PreparedStatement insertStatement = connection.preparedS
tatement(insertStatementStr);
connection = DriverManager.getConnection("jdbc:odbc:supp
ort","sa","");
PreparedStatement updateStatement = connection.preparedS
tatement(updateStatementStr);
connection = DriverManager.getConnection("jdbc:odbc:supp
ort","sa","");
PreparedStatement selectStatement = connection.preparedS
tatement(selectStatementStr);
updateStatement.executeUpdate();
// Retrieve the sequencer number
ResultSet rp = selectStatement.executeQuery();
rp.next();
int selanjutnya = rp.getInt(1);
requestId = selanjutnya;
insertStatement.setInt(1, requestId);
insertStatement.setString(2, email);
insertStatement.setString(3, software);
insertStatement.setString(4, os);
insertStatement.setString(5, problem);
insertStatement.executeUpdate();
PreparedStatement selectStatement1 = connection.prepared
Statement(selectCustomerStr);
selectStatement1.setString(1, email);
ResultSet rs = selectStatement1.executeQuery();
if (rs.next())
{
setFirstName(rs.getString("FNAME"));
setlastName(rs.getString("LNAME"));
setPhoneNumber(rs.getString("PHONE"));
//jika customer telah mendaftar, langsung ke response.jsp
registered = true;
}
else
{
//Jika customer belum mendaftar
registered = false;
}
rs.close();
rp.close();
updateStatement.close();
selectStatement.close();
selectStatement1.close();
}
finally {
if (connection != nill) {
try {
connection.close();
}
catch(SQLExceptionsqle) {}
}
}
}
//fungsi untuk mendaftar customer ke database
public void registerCustomer () throws SQLException {
Connection connection = null;
String insertStatementStr = "INSERT INTO CUSTOMERSjava VALUES(?,
?, ?, ?)";
try {
connection = DriverManager.getConnection("jdbc:odbc:support","sa
","");
PreparedStatement insertStatement = connection.preparedStatement
(insertStatementStr);
insertStatement.setString(1, email);
insertStatement.setString(2, firstName);
insertStatement.setString(3, lastName);
insertStatement.setString(4, phoneNumber);
insertStatement.executeUpdate();
}
finally {
if (connection != null) {
try {
connection.close();
}
catch (SQLException sqle) {}
}
}
}
}

Potrebbero piacerti anche