java的一道作业题,麻烦高手做下?先谢了 200
编写一程序,可以对银行储户的信息操作,提供以下功能(1)增加储户(2)修改储户信息(3)删除储户(4)查找储户(5)显示所有储户信息(6)退出完成提示(1)创建储户对象(...
编写一程序,可以对银行储户的信息操作,提供以下功能
(1)增加储户
(2)修改储户信息
(3)删除储户
(4)查找储户
(5) 显示所有储户信息
(6) 退出
完成提示
(1) 创建储户对象(帐号,用户名,余额)
(2) 操作时使用HashMap对象
(3) 数据存储在数据库Account表中
SQL中的数据↓
create table Account(
accountId varchar(15) primary key,
accountName varchar(20) not null,
balance smallmoney not null default 0
)
insert into account(accountId,accountName) values('2102001000','Tom')
insert into account values('2102001001','Tom',2000)
编写java程序连接数据库实现以上功能然后还要对数据进行操作,请高手帮忙花点时间写写,同时也是帮助自己提高,虽然是菜鸟问题,请高手花时间写下谢谢了,别出错误,我在JBU上运行要通过的话,200分就是你的 谢谢了 展开
(1)增加储户
(2)修改储户信息
(3)删除储户
(4)查找储户
(5) 显示所有储户信息
(6) 退出
完成提示
(1) 创建储户对象(帐号,用户名,余额)
(2) 操作时使用HashMap对象
(3) 数据存储在数据库Account表中
SQL中的数据↓
create table Account(
accountId varchar(15) primary key,
accountName varchar(20) not null,
balance smallmoney not null default 0
)
insert into account(accountId,accountName) values('2102001000','Tom')
insert into account values('2102001001','Tom',2000)
编写java程序连接数据库实现以上功能然后还要对数据进行操作,请高手帮忙花点时间写写,同时也是帮助自己提高,虽然是菜鸟问题,请高手花时间写下谢谢了,别出错误,我在JBU上运行要通过的话,200分就是你的 谢谢了 展开
9个回答
展开全部
真是麻烦,这里居然不能上传附件。
说明:
1、为了清晰回答你的问题,我共写了五个类。先分别说明一下各自的作用。
baidu.zhidao.anser.model.Account
不用讲了,这个类自然是代表银行帐户的DomainModel了。
baidu.zhidao.answer.util.DatabaseUtil
这个类负责获取数据库连接,以及关闭数据库资源(connection, preparedStatement, ResultSet),一个非常简单的工具类。
baidu.zhidao.answer.AccountManager
这是个interface,对外部暴露了操作account的方法。可以作为一个facade来使用。
baidu.zhidao.answer.AccountManagerImpl
这个类实现了AccountManager interface,内部操作数据库采用DatabaseUtil,是对account进行实际操作的实现类。
baidu.zhidao.answer.AccountManagerTest
这是一个Junit testcase,具体测试了AccountManager的各个方法,可以参照此类查看AccountManager的具体用法。
2.需要注意的地方
a.我看了你的题目要求,尤其是数据表的schema,猜测你是使用的sql server,也不知对不对?如果对的话,你需要拷贝sql server的jdbc driver,也就是msbase.jar,mssqlserver.jar,msutil.jar这三个jar到你的project library里面。
b.为简便期间,我没有把配置数据库参数以配置文件的方式写在外面,而是在DatabaseUtil里面预先设置的,你可能需要根据你的实际环境更改url,user,password。如果你真要改为配置文件方式也很简单,我这里就不多废话了。
3、这些仅仅是个toy,如果要用在实际项目中还有很多待改进的地方。不过足以应付你的需要了。
局限1:未实现批量增加/删除用户(你的问题里没要求)
局限2:事务无法跨越方法,总是在方法内部完成。其实要实现方法跨事务也不难,只需要将connection用ThreadLocal封装即可。(你的问题里也没要求,嘿嘿)
局限3:未采用数据库连接池,对每个客户端请求都是新开connection,系统开销大,不能应付过多的客户端同时调用。(未实现的理由同上)
局限4:对于数据库操作的异常未做良好的封装,为不影响用户界面的简单调用采用runtimeException抛出。所以在用户界面(web界面或者具体java application界面)中你需要对AccountManager的方法调用显示try/catch并处理异常,以提供给用户格式良好的出错信息。
PS:不要怪我未实现上述所说的局限之处,光写代码、说明加贴上来也花了我一个小时左右的时间,这些地方就留待你自己完善吧。
4、具体使用
你具体使用只要关心AccountManager即可,调用方法如下:
//实例化manager
AccountManager manager = AccountManagerImpl();
//增加或修改帐号
manager.saveAccount(account);
//通过account id查找
Account account = manager.findAccountById(id);
//通过account Name模糊查找
List accounts = manager.findAccountByName(account);
//删除帐号
manager.removeAccount(id);
具体可查看AccountManagerTest的代码
5、代码
------------------------------------------------------
package baidu.zhidao.answer.model;
import java.io.Serializable;
import java.math.BigDecimal;
public class Account implements Serializable
{
private String id;
private String name;
private BigDecimal balance = new BigDecimal(0);
public Account()
{
}
public Account(String id, String name)
{
this.id = id;
this.name = name;
}
public Account(String id, String name, BigDecimal balance)
{
this.id = id;
this.name = name;
this.balance = balance;
}
public BigDecimal getBalance()
{
return balance;
}
public void setBalance(BigDecimal balance)
{
this.balance = balance;
}
public String getId()
{
return id;
}
public void setId(String id)
{
this.id = id;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
}
------------------------------------------------------
package baidu.zhidao.answer.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DatabaseUtil
{
private static final String DEFAULT_DRIVER = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
private static final String DEFAULT_URL = "jdbc:microsoft:sqlserver://yourDatabaseIp:yourDatabasePort;DatabaseName=yourDatabase";
private static final String DEFAULT_USER = "yourDatabaseUser";
private static final String DEFAULT_PASSWORD = "password";
private DatabaseUtil()
{
}
public static Connection getConnection(String driver, String url,
String user, String password) throws Exception
{
driver = (driver == null || driver.length() == 0) ? DEFAULT_DRIVER : driver;
url = (url == null || url.length() == 0) ? DEFAULT_URL : url;
user = (user == null || user.length() == 0) ? DEFAULT_USER : user;
password = (password == null || password.length() == 0) ? DEFAULT_PASSWORD
: password;
Class.forName(driver).newInstance();
return DriverManager.getConnection(url, user, password);
}
public static Connection getConnection() throws Exception
{
return getConnection(null, null, null, null);
}
public static void close(Connection conn)
{
if (conn != null)
{
try
{
conn.close();
}
catch (SQLException ignore)
{
ignore.printStackTrace();
}
finally
{
conn = null;
}
}
}
public static void close(Statement stmt)
{
if (stmt != null)
{
try
{
stmt.close();
}
catch (SQLException ignore)
{
ignore.printStackTrace();
}
finally
{
stmt = null;
}
}
}
public static void close(PreparedStatement pstmt)
{
if (pstmt != null)
{
try
{
pstmt.close();
}
catch (SQLException ignore)
{
ignore.printStackTrace();
}
finally
{
pstmt = null;
}
}
}
public static void close(ResultSet rs)
{
if (rs != null)
{
try
{
rs.close();
}
catch (SQLException ignore)
{
ignore.printStackTrace();
}
finally
{
rs = null;
}
}
}
}
------------------------------------------------------
package baidu.zhidao.answer;
import java.util.List;
import baidu.zhidao.answer.model.Account;
public interface AccountManager
{
public abstract Account findAccountById(String accountId);
public abstract List findAccountByName(String accountName);
public abstract void saveAccount(Account account);
public abstract void removeAccount(String id);
public List findAll();
}
------------------------------------------------------
package baidu.zhidao.answer;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import baidu.zhidao.answer.model.Account;
import baidu.zhidao.answer.util.DatabaseUtil;
public class AccountManagerImpl implements AccountManager
{
/*
* (non-Javadoc)
*
* @see baidu.zhidao.answer.AccountManager#findAccountById()
*/
public Account findAccountById(String accountId)
{
if (accountId == null || accountId.length() == 0)
{
throw new IllegalArgumentException("accountId must be specified.");
}
String querySql = "SELECT * FROM Account WHERE accountId = ?";
List results = query(querySql, new Object[] { accountId });
if (results.size() > 0)
{
return (Account) results.get(0);
}
else
{
return null;
}
}
public List findAccountByName(String accountName)
{
if (accountName == null || accountName.length() == 0)
{
throw new IllegalArgumentException("accountName must be specified.");
}
String querySql = "SELECT * FROM Account WHERE accountName LIKE ?";
return query(querySql, new Object[] { "%" + accountName + "%" });
}
public List findAll()
{
return query("SELECT * FROM Account");
}
public void saveAccount(Account account)
{
//TODO need to implements update method
Account alreadyExist = findAccountById(account.getId());
String saveSql;
if (alreadyExist != null)
{
saveSql = "UPDATE Account SET accountName = ?, balance = ? WHERE accountId = ?";
}
else
{
saveSql = "INSERT INTO Account (accountId, accountName, balance) VALUES (?, ?, ?)";
}
Object[] parameters = new Object[3];
if (alreadyExist == null)
{
parameters[0] = account.getId();
parameters[1] = account.getName();
parameters[2] = account.getBalance();
}
else
{
parameters[0] = account.getName();
parameters[1] = account.getBalance();
parameters[2] = account.getId();
}
executeSQL(saveSql, parameters);
}
public void removeAccount(String id)
{
if (id == null || id.length() == 0)
{
throw new IllegalArgumentException("accountId must be specified.");
}
String deleteSql = "DELETE FROM Account WHERE accountId = ?";
executeSQL(deleteSql, new Object[] { id });
}
protected List query(String queryString)
{
return query(queryString, null);
}
protected List query(String queryString, Object[] parameters)
{
List results = new ArrayList();
Connection conn = null;
PreparedStatement psmt = null;
ResultSet rs = null;
try
{
conn = DatabaseUtil.getConnection();
psmt = conn.prepareStatement(queryString);
if (parameters != null && parameters.length > 0)
{
for (int i = 0; i < parameters.length; i++)
{
psmt.setObject(i + 1, parameters[i]);
}
}
rs = psmt.executeQuery();
while (rs.next())
{
Account account = new Account(rs.getString("accountId"), rs
.getString("accountName"), rs.getBigDecimal("balance"));
results.add(account);
}
return results;
}
catch (Exception e)
{
throw new RuntimeException(e);
}
finally
{
DatabaseUtil.close(rs);
DatabaseUtil.close(psmt);
DatabaseUtil.close(conn);
}
}
protected void executeSQL(String sql, Object[] parameters)
{
Connection conn = null;
PreparedStatement psmt = null;
ResultSet rs = null;
try
{
conn = DatabaseUtil.getConnection();
conn.setAutoCommit(false);
psmt = conn.prepareStatement(sql);
for (int i = 0; i < parameters.length; i++)
{
psmt.setObject(i + 1, parameters[i]);
}
psmt.execute();
conn.commit();
}
catch (Exception e)
{
try
{
conn.rollback();
}
catch (SQLException e1)
{
throw new RuntimeException(e1);
}
throw new RuntimeException(e);
}
finally
{
DatabaseUtil.close(rs);
DatabaseUtil.close(psmt);
DatabaseUtil.close(conn);
}
}
}
------------------------------------------------------
package baidu.zhidao.answer;
import java.math.BigDecimal;
import java.util.List;
import baidu.zhidao.answer.model.Account;
import junit.framework.TestCase;
public class AccountManagerTest extends TestCase
{
private AccountManager manager = new AccountManagerImpl();
private Account a1 = new Account("denis", "Denis Wang", new BigDecimal("10"));
private Account a2 = new Account("denis2", "Denis Wang2", new BigDecimal(
"11.22"));
private Account a3 = new Account("denis3", "Denis Wang3", new BigDecimal(
"14.00"));
private Account a4 = new Account("denis4", "Denis Wang4", new BigDecimal(
"15.21"));
protected void setUp() throws Exception
{
manager.saveAccount(a1);
manager.saveAccount(a2);
manager.saveAccount(a3);
manager.saveAccount(a4);
}
protected void tearDown() throws Exception
{
manager.removeAccount(a1.getId());
manager.removeAccount(a2.getId());
manager.removeAccount(a3.getId());
manager.removeAccount(a4.getId());
}
public void testFindAccountById()
{
Account denis = manager.findAccountById("denis");
assertEquals(a1.getId(), denis.getId());
assertEquals(a1.getName(), denis.getName());
assertTrue(a1.getBalance().compareTo(denis.getBalance()) == 0);
}
public void testFindAccountByName()
{
List results = manager.findAccountByName("Denis");
assertEquals(4, results.size());
}
public void testSaveOrUpdateAccount()
{
// test save new account action
manager.saveAccount(new Account("tempId", "tempName", new BigDecimal(
"11.22")));
assertEquals(5, manager.findAll().size());
manager.removeAccount("tempId");
assertEquals(4, manager.findAll().size());
// test update exist account action
Account denis2 = manager.findAccountById("denis2");
denis2.setBalance(denis2.getBalance().add(new BigDecimal("2")));
manager.saveAccount(denis2);
Account denis2LoadAgain = manager.findAccountById("denis2");
assertEquals(0, denis2.getBalance().compareTo(denis2LoadAgain.getBalance()));
assertEquals(4, manager.findAll().size());
}
public void testRemoveAccount()
{
manager.saveAccount(new Account("tempId", "tempName", new BigDecimal(
"11.22")));
assertEquals(5, manager.findAll().size());
manager.removeAccount("tempId");
assertEquals(4, manager.findAll().size());
}
}
------------------------------------------------------
说明:
1、为了清晰回答你的问题,我共写了五个类。先分别说明一下各自的作用。
baidu.zhidao.anser.model.Account
不用讲了,这个类自然是代表银行帐户的DomainModel了。
baidu.zhidao.answer.util.DatabaseUtil
这个类负责获取数据库连接,以及关闭数据库资源(connection, preparedStatement, ResultSet),一个非常简单的工具类。
baidu.zhidao.answer.AccountManager
这是个interface,对外部暴露了操作account的方法。可以作为一个facade来使用。
baidu.zhidao.answer.AccountManagerImpl
这个类实现了AccountManager interface,内部操作数据库采用DatabaseUtil,是对account进行实际操作的实现类。
baidu.zhidao.answer.AccountManagerTest
这是一个Junit testcase,具体测试了AccountManager的各个方法,可以参照此类查看AccountManager的具体用法。
2.需要注意的地方
a.我看了你的题目要求,尤其是数据表的schema,猜测你是使用的sql server,也不知对不对?如果对的话,你需要拷贝sql server的jdbc driver,也就是msbase.jar,mssqlserver.jar,msutil.jar这三个jar到你的project library里面。
b.为简便期间,我没有把配置数据库参数以配置文件的方式写在外面,而是在DatabaseUtil里面预先设置的,你可能需要根据你的实际环境更改url,user,password。如果你真要改为配置文件方式也很简单,我这里就不多废话了。
3、这些仅仅是个toy,如果要用在实际项目中还有很多待改进的地方。不过足以应付你的需要了。
局限1:未实现批量增加/删除用户(你的问题里没要求)
局限2:事务无法跨越方法,总是在方法内部完成。其实要实现方法跨事务也不难,只需要将connection用ThreadLocal封装即可。(你的问题里也没要求,嘿嘿)
局限3:未采用数据库连接池,对每个客户端请求都是新开connection,系统开销大,不能应付过多的客户端同时调用。(未实现的理由同上)
局限4:对于数据库操作的异常未做良好的封装,为不影响用户界面的简单调用采用runtimeException抛出。所以在用户界面(web界面或者具体java application界面)中你需要对AccountManager的方法调用显示try/catch并处理异常,以提供给用户格式良好的出错信息。
PS:不要怪我未实现上述所说的局限之处,光写代码、说明加贴上来也花了我一个小时左右的时间,这些地方就留待你自己完善吧。
4、具体使用
你具体使用只要关心AccountManager即可,调用方法如下:
//实例化manager
AccountManager manager = AccountManagerImpl();
//增加或修改帐号
manager.saveAccount(account);
//通过account id查找
Account account = manager.findAccountById(id);
//通过account Name模糊查找
List accounts = manager.findAccountByName(account);
//删除帐号
manager.removeAccount(id);
具体可查看AccountManagerTest的代码
5、代码
------------------------------------------------------
package baidu.zhidao.answer.model;
import java.io.Serializable;
import java.math.BigDecimal;
public class Account implements Serializable
{
private String id;
private String name;
private BigDecimal balance = new BigDecimal(0);
public Account()
{
}
public Account(String id, String name)
{
this.id = id;
this.name = name;
}
public Account(String id, String name, BigDecimal balance)
{
this.id = id;
this.name = name;
this.balance = balance;
}
public BigDecimal getBalance()
{
return balance;
}
public void setBalance(BigDecimal balance)
{
this.balance = balance;
}
public String getId()
{
return id;
}
public void setId(String id)
{
this.id = id;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
}
------------------------------------------------------
package baidu.zhidao.answer.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DatabaseUtil
{
private static final String DEFAULT_DRIVER = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
private static final String DEFAULT_URL = "jdbc:microsoft:sqlserver://yourDatabaseIp:yourDatabasePort;DatabaseName=yourDatabase";
private static final String DEFAULT_USER = "yourDatabaseUser";
private static final String DEFAULT_PASSWORD = "password";
private DatabaseUtil()
{
}
public static Connection getConnection(String driver, String url,
String user, String password) throws Exception
{
driver = (driver == null || driver.length() == 0) ? DEFAULT_DRIVER : driver;
url = (url == null || url.length() == 0) ? DEFAULT_URL : url;
user = (user == null || user.length() == 0) ? DEFAULT_USER : user;
password = (password == null || password.length() == 0) ? DEFAULT_PASSWORD
: password;
Class.forName(driver).newInstance();
return DriverManager.getConnection(url, user, password);
}
public static Connection getConnection() throws Exception
{
return getConnection(null, null, null, null);
}
public static void close(Connection conn)
{
if (conn != null)
{
try
{
conn.close();
}
catch (SQLException ignore)
{
ignore.printStackTrace();
}
finally
{
conn = null;
}
}
}
public static void close(Statement stmt)
{
if (stmt != null)
{
try
{
stmt.close();
}
catch (SQLException ignore)
{
ignore.printStackTrace();
}
finally
{
stmt = null;
}
}
}
public static void close(PreparedStatement pstmt)
{
if (pstmt != null)
{
try
{
pstmt.close();
}
catch (SQLException ignore)
{
ignore.printStackTrace();
}
finally
{
pstmt = null;
}
}
}
public static void close(ResultSet rs)
{
if (rs != null)
{
try
{
rs.close();
}
catch (SQLException ignore)
{
ignore.printStackTrace();
}
finally
{
rs = null;
}
}
}
}
------------------------------------------------------
package baidu.zhidao.answer;
import java.util.List;
import baidu.zhidao.answer.model.Account;
public interface AccountManager
{
public abstract Account findAccountById(String accountId);
public abstract List findAccountByName(String accountName);
public abstract void saveAccount(Account account);
public abstract void removeAccount(String id);
public List findAll();
}
------------------------------------------------------
package baidu.zhidao.answer;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import baidu.zhidao.answer.model.Account;
import baidu.zhidao.answer.util.DatabaseUtil;
public class AccountManagerImpl implements AccountManager
{
/*
* (non-Javadoc)
*
* @see baidu.zhidao.answer.AccountManager#findAccountById()
*/
public Account findAccountById(String accountId)
{
if (accountId == null || accountId.length() == 0)
{
throw new IllegalArgumentException("accountId must be specified.");
}
String querySql = "SELECT * FROM Account WHERE accountId = ?";
List results = query(querySql, new Object[] { accountId });
if (results.size() > 0)
{
return (Account) results.get(0);
}
else
{
return null;
}
}
public List findAccountByName(String accountName)
{
if (accountName == null || accountName.length() == 0)
{
throw new IllegalArgumentException("accountName must be specified.");
}
String querySql = "SELECT * FROM Account WHERE accountName LIKE ?";
return query(querySql, new Object[] { "%" + accountName + "%" });
}
public List findAll()
{
return query("SELECT * FROM Account");
}
public void saveAccount(Account account)
{
//TODO need to implements update method
Account alreadyExist = findAccountById(account.getId());
String saveSql;
if (alreadyExist != null)
{
saveSql = "UPDATE Account SET accountName = ?, balance = ? WHERE accountId = ?";
}
else
{
saveSql = "INSERT INTO Account (accountId, accountName, balance) VALUES (?, ?, ?)";
}
Object[] parameters = new Object[3];
if (alreadyExist == null)
{
parameters[0] = account.getId();
parameters[1] = account.getName();
parameters[2] = account.getBalance();
}
else
{
parameters[0] = account.getName();
parameters[1] = account.getBalance();
parameters[2] = account.getId();
}
executeSQL(saveSql, parameters);
}
public void removeAccount(String id)
{
if (id == null || id.length() == 0)
{
throw new IllegalArgumentException("accountId must be specified.");
}
String deleteSql = "DELETE FROM Account WHERE accountId = ?";
executeSQL(deleteSql, new Object[] { id });
}
protected List query(String queryString)
{
return query(queryString, null);
}
protected List query(String queryString, Object[] parameters)
{
List results = new ArrayList();
Connection conn = null;
PreparedStatement psmt = null;
ResultSet rs = null;
try
{
conn = DatabaseUtil.getConnection();
psmt = conn.prepareStatement(queryString);
if (parameters != null && parameters.length > 0)
{
for (int i = 0; i < parameters.length; i++)
{
psmt.setObject(i + 1, parameters[i]);
}
}
rs = psmt.executeQuery();
while (rs.next())
{
Account account = new Account(rs.getString("accountId"), rs
.getString("accountName"), rs.getBigDecimal("balance"));
results.add(account);
}
return results;
}
catch (Exception e)
{
throw new RuntimeException(e);
}
finally
{
DatabaseUtil.close(rs);
DatabaseUtil.close(psmt);
DatabaseUtil.close(conn);
}
}
protected void executeSQL(String sql, Object[] parameters)
{
Connection conn = null;
PreparedStatement psmt = null;
ResultSet rs = null;
try
{
conn = DatabaseUtil.getConnection();
conn.setAutoCommit(false);
psmt = conn.prepareStatement(sql);
for (int i = 0; i < parameters.length; i++)
{
psmt.setObject(i + 1, parameters[i]);
}
psmt.execute();
conn.commit();
}
catch (Exception e)
{
try
{
conn.rollback();
}
catch (SQLException e1)
{
throw new RuntimeException(e1);
}
throw new RuntimeException(e);
}
finally
{
DatabaseUtil.close(rs);
DatabaseUtil.close(psmt);
DatabaseUtil.close(conn);
}
}
}
------------------------------------------------------
package baidu.zhidao.answer;
import java.math.BigDecimal;
import java.util.List;
import baidu.zhidao.answer.model.Account;
import junit.framework.TestCase;
public class AccountManagerTest extends TestCase
{
private AccountManager manager = new AccountManagerImpl();
private Account a1 = new Account("denis", "Denis Wang", new BigDecimal("10"));
private Account a2 = new Account("denis2", "Denis Wang2", new BigDecimal(
"11.22"));
private Account a3 = new Account("denis3", "Denis Wang3", new BigDecimal(
"14.00"));
private Account a4 = new Account("denis4", "Denis Wang4", new BigDecimal(
"15.21"));
protected void setUp() throws Exception
{
manager.saveAccount(a1);
manager.saveAccount(a2);
manager.saveAccount(a3);
manager.saveAccount(a4);
}
protected void tearDown() throws Exception
{
manager.removeAccount(a1.getId());
manager.removeAccount(a2.getId());
manager.removeAccount(a3.getId());
manager.removeAccount(a4.getId());
}
public void testFindAccountById()
{
Account denis = manager.findAccountById("denis");
assertEquals(a1.getId(), denis.getId());
assertEquals(a1.getName(), denis.getName());
assertTrue(a1.getBalance().compareTo(denis.getBalance()) == 0);
}
public void testFindAccountByName()
{
List results = manager.findAccountByName("Denis");
assertEquals(4, results.size());
}
public void testSaveOrUpdateAccount()
{
// test save new account action
manager.saveAccount(new Account("tempId", "tempName", new BigDecimal(
"11.22")));
assertEquals(5, manager.findAll().size());
manager.removeAccount("tempId");
assertEquals(4, manager.findAll().size());
// test update exist account action
Account denis2 = manager.findAccountById("denis2");
denis2.setBalance(denis2.getBalance().add(new BigDecimal("2")));
manager.saveAccount(denis2);
Account denis2LoadAgain = manager.findAccountById("denis2");
assertEquals(0, denis2.getBalance().compareTo(denis2LoadAgain.getBalance()));
assertEquals(4, manager.findAll().size());
}
public void testRemoveAccount()
{
manager.saveAccount(new Account("tempId", "tempName", new BigDecimal(
"11.22")));
assertEquals(5, manager.findAll().size());
manager.removeAccount("tempId");
assertEquals(4, manager.findAll().size());
}
}
------------------------------------------------------
展开全部
他的意思是用JBU来操作,是吧 呵呵
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你的JBUILDER的具体版本号?
还有用WEB还是还是C/S
用的什么数据库...
还有用WEB还是还是C/S
用的什么数据库...
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
不要投机取巧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
关注中~~
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询