package ch.sahits;
import java.sql.Date;
import java.util.Hashtable;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
/**
* This class represents the database table
* USER.
*/
public class Foo {
/** <code>name</code> holds the value of the field NAME */
private String name;
/** <code>surname</code> holds the value of the field SURNAME */
private String surname;
/** <code>email</code> holds the value of the field EMAIL */
private String email;
/** <code>birthDate</code> holds the value of the field BIRTH_DATE */
private Date birthDate;
/**
* Constructor initializes the bean with a list of values.
* @param values Hashtable<String,Object>. If the Object represents
* an unboxed primitive type, the Object must be of type String.
*/
public Foo(Hashtable<String,Object> values){
init(values);
}
/**
* Initialize the bean with a list of values.
* @param values Hashtable<String,Object>. If the Object represents
* an unboxed primitive type, the Object must be of type String.
*/
private void init(Hashtable<String,Object> values){
if (values.contains("NAME")){
setName((String)values.get("NAME"));
}
if (values.contains("SURNAME")){
setSurname((String)values.get("SURNAME"));
}
if (values.contains("EMAIL")){
setEmail((String)values.get("EMAIL"));
}
if (values.contains("BIRTH_DATE")){
setBirthDate((Date)values.get("BIRTH_DATE"));
}
}
/**
* Retrieve the value of the field NAME.
* @return the value of the field
*/
public String getName(){
return name;
}
/**
* Set the value of the field NAME.
* @param name value to be set for NAME
*/
public void setName(String name){
this.name = name;
}
/**
* Retrieve the value of the field SURNAME.
* @return the value of the field
*/
public String getSurname(){
return surname;
}
/**
* Set the value of the field SURNAME.
* @param surname value to be set for SURNAME
*/
public void setSurname(String surname){
this.surname = surname;
}
/**
* Retrieve the value of the field EMAIL.
* @return the value of the field
*/
public String getEmail(){
return email;
}
/**
* Set the value of the field EMAIL.
* @param email value to be set for EMAIL
*/
public void setEmail(String email){
this.email = email;
}
/**
* Retrieve the value of the field BIRTH_DATE.
* @return the value of the field
*/
public Date getBirthDate(){
return birthDate;
}
/**
* Set the value of the field BIRTH_DATE.
* @param birthDate value to be set for BIRTH_DATE
*/
public void setBirthDate(Date birthDate){
this.birthDate = birthDate;
}
/**
* Remove the record from the database indicated by the key values of this object.
* @return number of deleted records.
* @throws SQLException
* @throws ClassNotFoundException
*/
public int delete() throws SQLException, ClassNotFoundException {
String sql = "delete from USER WHERE EMAIL='" + getEmail() + "'";
Connection con = getConnection();
Statement stmt = con.createStatement();
int result = stmt.executeUpdate(sql);
stmt.close();
con.close();
return result;
}
/**
* Set up a connection to the database
* @return connection
* @throws ClassNotFoundException
* @throws SQLException
*/
private Connection getConnection() throws ClassNotFoundException,
SQLException {
Class.forName("oracle.jdbc.driver.OracleDriver");
return DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:name", "sys", "name");
}
}