Java Reference
In-Depth Information
conn
.
close
();
}
/** Add one user to the list, both in-memory and on disk. */
public
public synchronized
synchronized
void
void
addUser
(
User nu
)
throws
throws
IOException
,
SQLException
{
// Add it to the in-memory list
super
super
.
addUser
(
nu
);
// Copy fields from user to DB
// XXX WAY INCOMPLETE NOW
int
int
i
=
1
;
addUserStmt
.
setString
(
i
++,
nu
.
getName
());
addUserStmt
.
setString
(
i
++,
nu
.
getPassword
());
addUserStmt
.
setString
(
i
++,
nu
.
getFirstName
());
addUserStmt
.
setString
(
i
++,
nu
.
getLastName
());
addUserStmt
.
setString
(
i
++,
nu
.
getEmail
());
addUserStmt
.
setString
(
i
++,
nu
.
getCity
());
addUserStmt
.
setString
(
i
++,
nu
.
getProvince
());
addUserStmt
.
setString
(
i
++,
nu
.
getCountry
());
java
.
sql
.
Date
now
=
new
new
java
.
sql
.
Date
(
System
.
currentTimeMillis
());
addUserStmt
.
setDate
(
i
++,
now
);
addUserStmt
.
setDate
(
i
++,
now
);
addUserStmt
.
setString
(
i
++,
nu
.
getSkin
());
addUserStmt
.
setBoolean
(
i
++,
false
false
);
addUserStmt
.
setBoolean
(
i
++,
false
false
);
--
i
;
iif
(
i
!=
13
) {
System
.
out
.
println
(
"Warning: not enough fields set! i = "
+
i
);
}
// Store in persistent DB
addUserStmt
.
executeUpdate
();
}
public
public
void
void
deleteUser
(
String nick
)
throws
throws
SQLException
{
// Find the user object
User u
=
getUser
(
nick
);
iif
(
u
==
null
null
) {
throw
throw new
new
SQLException
(
"User "
+
nick
+
" not in in-memory DB"
);
}
deleteUserStmt
.
setString
(
1
,
nick
);
int
int
n
=
deleteUserStmt
.
executeUpdate
();
iif
(
n
!=
1
) {
// not just one row??