Methods Summary |
---|
private void | close(java.sql.PreparedStatement ps)
if (ps != null) {
try {
ps.close();
} catch (SQLException e) {
}
}
|
private void | close(java.sql.ResultSet rs)
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
}
}
|
private void | close(java.sql.Connection conn)
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
}
}
|
public Account | getAccount(java.lang.String acctNumber)
Connection conn = null;
try {
conn = DriverManager.getConnection(this.dbUrl);
return getAccount(acctNumber, conn);
} catch (SQLException e) {
throw new DataSourceException(e);
} finally {
close(conn);
}
|
Account | getAccount(java.lang.String acctNumber, java.sql.Connection conn)
PreparedStatement ps = null;
ResultSet rs = null;
try {
ps = conn.prepareStatement(
"SELECT balance, acctType " +
"FROM Accounts " +
"WHERE acctNumber = ?");
ps.setString(1, acctNumber);
Account acct = null;
rs = ps.executeQuery();
if (rs.next()) {
double balance = rs.getDouble("balance");
String acctTypeStr = rs.getString("acctType");
int acctType = getAccountType(acctTypeStr);
acct = new Account(acctType, acctNumber, balance);
}
return acct;
} finally {
close(rs);
close(ps);
}
|
int | getAccountType(java.lang.String acctTypeStr)
if ("SA".equals(acctTypeStr)) {
return Account.SAVINGS;
}
if ("CH".equals(acctTypeStr)) {
return Account.CHECKING;
}
throw new DataSourceException("Unknown account type: " + acctTypeStr);
|
public static synchronized com.oreilly.mock.AccountFactory | getInstance()
if (instance == null) {
instance = new AccountFactory("sun.jdbc.odbc.JdbcOdbcDriver",
"jdbc:odbc:banking");
}
return instance;
|
public static void | main(java.lang.String[] args)
AccountFactory acctFactory = AccountFactory.getInstance();
Account acct = acctFactory.getAccount("0001");
PrintWriter pw = new PrintWriter(System.out);
acct.writeCsv(pw);
pw.flush();
|