Java Reference
In-Depth Information
ResultSet rs
=
stmt
.
executeQuery
(
"select * from users"
);
while
while
(
rs
.
next
()) {
//name:password:fullname:City:Prov:Country:privs
// Get the fields from the query.
// Could be an Entity EJB with CMP: this is unnecessarily
// chummy with the SQL. See CreateUserDatabase.java for field#'s!
int
int
i
=
1
;
String nick
=
rs
.
getString
(
i
++).
trim
();
String pass
=
rs
.
getString
(
i
++).
trim
();
// System.err.println(nick + " (" + pass + ")");
String first
=
rs
.
getString
(
i
++);
String last
=
rs
.
getString
(
i
++);
String email
=
rs
.
getString
(
i
++);
String city
=
rs
.
getString
(
i
++);
String prov
=
rs
.
getString
(
i
++);
String ctry
=
rs
.
getString
(
i
++);
java
.
sql
.
Date
credt
=
rs
.
getDate
(
i
++);
java
.
sql
.
Date
lastlog
=
rs
.
getDate
(
i
++);
String skin
=
rs
.
getString
(
i
++);
boolean
boolean
editPrivs
=
rs
.
getBoolean
(
i
++);
boolean
boolean
adminPrivs
=
rs
.
getBoolean
(
i
++);
// Construct a user object from the fields
// System.out.println("Constructing User object");
User u
=
new
new
User
(
nick
,
pass
,
first
,
last
,
email
,
prov
,
ctry
,
credt
,
lastlog
,
skin
,
editPrivs
,
adminPrivs
);
// System.out.println("Adding User object " + u + " to " + users);
// Add it to the in-memory copy.
users
.
add
(
u
);
// System.err.println("User " + nick + "; pass " + pass.charAt(0));
}
rs
.
close
();
// All done with that resultset
stmt
.
close
();
// Set up the PreparedStatements now so we don't have to
// re-create them each time needed.
addUserStmt
=
conn
.
prepareStatement
(
SQL_INSERT_USER
);
setPasswordStatement
=
conn
.
prepareStatement
(
"update users SET password = ? where name = ?"
);
setLastLoginStmt
=
conn
.
prepareStatement
(
"update users SET lastLogin = ? where name = ?"
);
deleteUserStmt
=
conn
.
prepareStatement
(
"delete from users where name = ?"
);