写C#好几年,刚刚涉及Java,新手一枚。请教各位IT大咖:
在不用SSH和SSM的纯代码情况下,更新和查询数据库,如何根据业务对象属性是否为空值,动态生成SQL语句和Statement参数表,执行操作?
或者自定义的业务对象如何强制所有值空值都是null?
1、自定义业务对象
/** *@ ClassName: UniAccount *@ Function: UniAccount的业务对象类 *@ Author: Winder *@ Date: 2017/9/26 *@ Description: 根据数据库的内容生成UniAccount业务对象代码 *@ Version: V6.0 *@ Updateing Records: *@ Date Auther Record *@ 2017/9/26 14:22:57 Winder Creating */ package Winder.Uas.Bean; import java.math.BigDecimal; import java.util.Date; /** * */ public class UniAccount { private int AccountId ; private string StateId ; private string AccountName ; private string AccountMobile ; private string AccountEmail ; private string IdCard ; private string AccountPwd ; private boolean IsActivate ; private DateTime DateCreated ; private string Memo ; public string getAccountId() { return AccountId; } public void setAccountId(string accountId) { this.AccountId =accountId; } public string getStateId() { return StateId; } public void setStateId(string stateId) { this.StateId =stateId; } public string getAccountName() { return AccountName; } public void setAccountName(string accountName) { this.AccountName =accountName; } public string getAccountMobile() { return AccountMobile; } public void setAccountMobile(string accountMobile) { this.AccountMobile =accountMobile; } public string getAccountEmail() { return AccountEmail; } public void setAccountEmail(string accountEmail) { this.AccountEmail =accountEmail; } public string getIdCard() { return IdCard; } public void setIdCard(string idCard) { this.IdCard =idCard; } public string getAccountPwd() { return AccountPwd; } public void setAccountPwd(string accountPwd) { this.AccountPwd =accountPwd; } public boolean getIsActivate() { return IsActivate; } public void setIsActivate(boolean isActivate) { this.IsActivate =isActivate; } public DateTime getDateCreated() { return DateCreated; } public void setDateCreated(DateTime dateCreated) { this.DateCreated =dateCreated; } }
package Winder.Uas.Dal; import java.util.List; import java.util.ArrayList; import java.util.Hashtable; import java.sql.ResultSet; import Winder.Uas.Bean; import Winder.Uas.IDal; import Winder.Uas.Util; /** *@ Function: dbo.UniAccount的数据访问实现类 */ public class UniAccountDao implements IUniAccountDao { //UniAccount数据库连接字符串 Propertities prop=new Properties(); prop.load(new FileInputStream("config.properties")); private static final String conStr = prop.getProperty("Wangzl_AConnectionString"); /** * 添加UniAccount对象 * <param name="uniAccount">UniAccount</param> * <returns>boolean</returns> */ public boolean AddUniAccount(UniAccount uniAccount) { } /*根据UniAccount属性参数批量删除UniAccount对象*/ public boolean DeleteUniAccounts(UniAccount uniAccount) { } /** * 通过包含主键的UniAccount更新UniAccount对象 */ public boolean UpdateUniAccount(UniAccount uniAccount) { } /** * 根据UniAccount对象参数查询某一条UniAccount对象集合 */ public IList<UniAccount> GetUniAccounts(UniAccount uniAccount) { } }
3、更新和查询数据库,如何根据业务对象属性是否为空值,动态生成SQL语句和Statement参数表,执行操作?
或者自定义的业务对象如何强制所有值空值都是null?