JdbcTemplate (select * from xx where id = ?)
来源:互联网 发布:监控拓扑图软件 编辑:程序博客网 时间:2024/05/05 00:28
public ArrayList getByPrimaryKey() throws Exception
{
final ArrayList info = new ArrayList();
//final PackMap packmap = new PackMap();
if(packMap == null || tableName == null)
throw new NullPointerException(this.CLASS_PATH_NAME+
".getByPrimaryKey() ->/nhandset or tableName is Null...");
try
{
StringBuffer sqlStr = addKeyConstraintsToSql(packMap,DaoUtils.getSelectSqlFront(tableName));
log.info("sql String () SQL -> "+sqlStr.toString()+packMap.getTypeName());
jdbcTemplate.query(sqlStr.toString(),
new PreparedStatementSetter()
{
public void setValues(PreparedStatement pstmt) throws SQLException
{
setPrepStmt(pstmt,packMap);
}
},
new RowCallbackHandler()
{
public void processRow(ResultSet rs)throws SQLException
{
PackMap packMap = new PackMap();
packMap.setPack(rs.getString("Package"));
packMap.setTypeName(rs.getString("Type"));
info.add(packMap);
}
}
);
//log.info("int out handset size() : " + info.size());
}catch(Exception e){
log.error("getByPrimaryKey() ->"+e);
throw new Exception(this.CLASS_PATH_NAME+"getByPrimaryKey() error-->"+e);
}
if(info == null || info.size() == 0){
return null;
}
else
if(info.size() > 0)
return info;
else
throw new Exception(this.CLASS_PATH_NAME+".getByPrimaryKey() error -> One key but more than two result");
}
private StringBuffer addKeyConstraintsToSql(PackMap obj,StringBuffer buffer)
{
StringBuffer tempBuffer = new StringBuffer();
tempBuffer = DaoUtils.addStringConstraint(type,obj.getTypeName(), tempBuffer);
buffer = DaoUtils.addWhereClauseStatement(tempBuffer, buffer);
return buffer;
}
private void setPrepStmt(PreparedStatement pstmt, PackMap obj) throws SQLException
{
int i = 1;
if(obj.getPack()!= null)
{
pstmt.setString(i++, obj.getPack().trim());
}
if(obj.getTypeName()!= null)
{
pstmt.setString(i++,obj.getTypeName());
}
}
- JdbcTemplate (select * from xx where id = ?)
- select * from sample where id = id
- if exists (select * from dbo.sysobjects where id = object_id ..
- select name from syscolumns where id=object_id(\'表名\')
- select * from table1 where id =‘1’ for update
- select count(1) from user where id=2
- 获取最新(最大)值的一条数据select * from dbname where id=(select max(id) from dbname)
- SELECT count(ID) FROM LM_Photos WHERE (userid = @userid) 报错的原因
- 查所有表名 select name from syscolumns where id=object_id('ReorgDB.dbo.Reorg_ReorgInfor')
- 句话是什么意思?if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[PerPer
- 有多少行? SELECT rows FROM sysindexes WHERE id = OBJECT_ID('table_name') AND indid < 2
- 共享锁select * from t1 where id=2 LOCK IN SHARE MODE;
- if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[PerPer
- MySQL 查询 select * from table where id in 如何提高效率?
- strSQL = "Select * From " & strTableName & " Where False "
- select * from table where 1=1
- select * from table where 1=1
- select * from table where 1=1
- 徹底刪除oracle
- 后台自动发送邮件的程序(java mail,web版)①
- java学习的一些主线思路
- 后台自动发送邮件的程序(java mail,web版)②
- 国内外 Java Script 经典封装
- JdbcTemplate (select * from xx where id = ?)
- 从 .mp3 转为 .amr 格式 流媒体
- mp3制作成swf,然后挂马
- 半小时精通正则表达式
- [摘]设计模式之Factory
- 五种常见 Ajax 模式
- SQL数据导入导出问题超级大罗列
- [SQL server]存储过程事务
- 慎用Visual C++ 2005