Menu

[r2667]: / trunk / ch.sahits.codegen.test / fragments / headless_test / Foo5.java  Maximize  Restore  History

Download this file

149 lines (131 with data), 3.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
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");
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.