📄 voiceuserdao.java
字号:
int intID = rs.getInt("ID"); if(!rs.wasNull()) model.setId(new Integer(intID)); String strNAME =rs.getString("NAME"); if(!rs.wasNull()) model.setName(strNAME.trim()); String strPASSWORD =rs.getString("PASSWORD"); if(!rs.wasNull()) model.setPassword(strPASSWORD.trim()); int intTYPE = rs.getInt("TYPE"); if(!rs.wasNull()) model.setType(new Integer(intTYPE)); String strEMAIL =rs.getString("EMAIL"); if(!rs.wasNull()) model.setEmail(strEMAIL.trim()); list.add(model); } rs.close(); prepStmt.close(); return list ; } public ArrayList supplements(Connection aConnection,VoiceUserValueObject[] manyVoiceUserValueObject,int start,int end) throws SQLException { //---- variable sql be provided througth analyze the ValueObject StringBuffer sql = new StringBuffer("SELECT A.ID, A.NAME, A.PASSWORD, A.TYPE, A.EMAIL FROM VOICE_USER A WHERE 1 = 0 " ); for(int i=0;i<manyVoiceUserValueObject.length;i++){ sql.append( " or ( 1=1 "); if(manyVoiceUserValueObject[i].getId()!=null){ sql.append(" and A.ID=").append(manyVoiceUserValueObject[i].getId()); } if(manyVoiceUserValueObject[i].getName()!=null&&!manyVoiceUserValueObject[i].getName().equals("")){ sql.append(" and A.NAME='"+manyVoiceUserValueObject[i].getName()).append("'"); } if(manyVoiceUserValueObject[i].getPassword()!=null&&!manyVoiceUserValueObject[i].getPassword().equals("")){ sql.append(" and A.PASSWORD='"+manyVoiceUserValueObject[i].getPassword()).append("'"); } if(manyVoiceUserValueObject[i].getType()!=null){ sql.append(" and A.TYPE=").append(manyVoiceUserValueObject[i].getType()); } if(manyVoiceUserValueObject[i].getEmail()!=null&&!manyVoiceUserValueObject[i].getEmail().equals("")){ sql.append(" and A.EMAIL='"+manyVoiceUserValueObject[i].getEmail()).append("'"); } sql.append(")"); } //-----Result between variable start and variable end if (start != -1 && end != -1){ String mainSql = sql.toString(); sql = new StringBuffer("select * from ( select a.*,rownum as tmprow from (").append(mainSql).append(") a where rownum <=").append(end).append(") where tmprow>= ").append(start); } ResultSet rs = null; ArrayList list = new ArrayList(); PreparedStatement prepStmt = aConnection.prepareStatement( sql.toString() ); rs = prepStmt.executeQuery(); while( rs.next() ) { VoiceUserValueObject model = new VoiceUserValueObject(); int intID = rs.getInt("ID"); if(!rs.wasNull()) model.setId(new Integer(intID)); String strNAME =rs.getString("NAME"); if(!rs.wasNull()) model.setName(strNAME.trim()); String strPASSWORD =rs.getString("PASSWORD"); if(!rs.wasNull()) model.setPassword(strPASSWORD.trim()); int intTYPE = rs.getInt("TYPE"); if(!rs.wasNull()) model.setType(new Integer(intTYPE)); String strEMAIL =rs.getString("EMAIL"); if(!rs.wasNull()) model.setEmail(strEMAIL.trim()); list.add(model); } rs.close(); prepStmt.close(); return list ; } public int size(Connection aConnection,VoiceUserQueryValue aVoiceUserQueryValue) throws SQLException { StringBuffer sql = new StringBuffer("select count(*) tsize from VOICE_USER A where 1=1 " ); String condition = aVoiceUserQueryValue.toSql(); sql.append(condition); ResultSet rs = null; int size = 0; PreparedStatement prepStmt = aConnection.prepareStatement( sql.toString() ); rs = prepStmt.executeQuery(); if(rs.next()) size = rs.getInt(1); rs.close(); prepStmt.close(); return size ; } public ArrayList all(Connection aConnection) throws SQLException { StringBuffer sql = new StringBuffer("SELECT A.ID, A.NAME, A.PASSWORD, A.TYPE, A.EMAIL FROM VOICE_USER A WHERE 1 = 1 " ); ResultSet rs = null; ArrayList list = new ArrayList(); PreparedStatement prepStmt = aConnection.prepareStatement( sql.toString() ); rs = prepStmt.executeQuery(); while( rs.next() ) { VoiceUserValueObject model = new VoiceUserValueObject(); int intID = rs.getInt("ID"); if(!rs.wasNull()) model.setId(new Integer(intID)); String strNAME =rs.getString("NAME"); if(!rs.wasNull()) model.setName(strNAME.trim()); String strPASSWORD =rs.getString("PASSWORD"); if(!rs.wasNull()) model.setPassword(strPASSWORD.trim()); int intTYPE = rs.getInt("TYPE"); if(!rs.wasNull()) model.setType(new Integer(intTYPE)); String strEMAIL =rs.getString("EMAIL"); if(!rs.wasNull()) model.setEmail(strEMAIL.trim()); list.add(model); } rs.close(); prepStmt.close(); return list ; } public ArrayList selectByQueryValue(Connection aConnection,VoiceUserQueryValue aVoiceUserQueryValue,int start,int end) throws SQLException { //---- variable sql be provided througth analyze the ValueObject StringBuffer sql = new StringBuffer("SELECT A.ID, A.NAME, A.PASSWORD, A.TYPE, A.EMAIL FROM VOICE_USER A WHERE 1 = 1 " ); String condition = aVoiceUserQueryValue.toSql(); sql.append(condition); //-----Result between variable start and variable end if (start != -1 && end != -1){ String mainSql = sql.toString(); sql = new StringBuffer("select * from ( select a.*,rownum as tmprow from (").append(mainSql).append(") a where rownum <=").append(end).append(") where tmprow>= ").append(start); } ResultSet rs = null; ArrayList list = new ArrayList(); PreparedStatement prepStmt = aConnection.prepareStatement( sql.toString() ); rs = prepStmt.executeQuery(); while( rs.next() ) { VoiceUserValueObject model = new VoiceUserValueObject(); int intID = rs.getInt("ID"); if(!rs.wasNull()) model.setId(new Integer(intID)); String strNAME =rs.getString("NAME"); if(!rs.wasNull()) model.setName(strNAME.trim()); String strPASSWORD =rs.getString("PASSWORD"); if(!rs.wasNull()) model.setPassword(strPASSWORD.trim()); int intTYPE = rs.getInt("TYPE"); if(!rs.wasNull()) model.setType(new Integer(intTYPE)); String strEMAIL =rs.getString("EMAIL"); if(!rs.wasNull()) model.setEmail(strEMAIL.trim()); list.add(model); } rs.close(); prepStmt.close(); return list ; } public VoiceUserValueObject getByPrimaryKey(Connection aConnection,Integer id) throws SQLException { String sql = "select * from VOICE_USER A where 1=1 and A.ID=?"; ResultSet rs = null; ArrayList list = new ArrayList(); PreparedStatement prepStmt = aConnection.prepareStatement( sql.toString() ); prepStmt.setInt(1,id.intValue()); rs = prepStmt.executeQuery(); while( rs.next() ) { VoiceUserValueObject model = new VoiceUserValueObject(); model.setId(id); String strNAME =rs.getString("NAME"); if(!rs.wasNull()) model.setName(strNAME.trim()); String strPASSWORD =rs.getString("PASSWORD"); if(!rs.wasNull()) model.setPassword(strPASSWORD.trim()); int intTYPE = rs.getInt("TYPE"); if(!rs.wasNull()) model.setType(new Integer(intTYPE)); String strEMAIL =rs.getString("EMAIL"); if(!rs.wasNull()) model.setEmail(strEMAIL.trim()); list.add(model); } rs.close(); prepStmt.close(); return list.size()==0?null:(VoiceUserValueObject)list.get(0) ; } public void deleteByPrimaryKey(Connection aConnection,Integer id) throws SQLException { String sql = "delete from VOICE_USER where 1=1 and ID=?"; PreparedStatement prepStmt = aConnection.prepareStatement( sql.toString() ); prepStmt.setInt(1,id.intValue()); prepStmt.executeUpdate(); } //-----Codes above generated by dao }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -