Spring JDBCTemplate學習筆記

2021-07-22 02:50:50 字數 2339 閱讀 8566

title: spring jdbctemplate學習筆記

date: 2016-8-26

author: kagula

env: spring 3.1.2.release, oracle 11gr2

這裡記下示例**片段,免得過一段時間又忘記了。

string sql = "insert into citycodemap (idcitycodemap,icbccode,chinapetrocode,cityname)"

+ "values(seq_citycodemap.nextval,?,?,?)";

this.getjdbctemplate().update(sql,

new object);

string sql = "delete from cashbox where idcashbox=?";

this.getjdbctemplate().update(sql,new object);

createtime += " 00:00:00";//expect format is 2016-08-26 00:00:00

timestamp ts = timestamp.valueof(createtime);

sql= "update paymentnumber set idcashbox=? where createtime=? and idstationinfo=?";

this.jdbctemplate.update(sql,new object);

單值返回

public boolean i***ist(string createtime,int idstationinfo)

); if(count>0)

return false;

}

單值多條記錄

string stationid = this.getjdbctemplate().queryforobject("select stationid from stationinfotable where idstationinfo=?", 

new object,string.class);

單條記錄

public sessionuserinfo query(string username)

, @override

public sessionuserinfo maprow(resultset rs, int rownum) throws sqlexception });

}catch(exception e)

return sui;

}

多條記錄

示例一:返回list型別

sql = "select a.*,b.cityname from escortmanager a left join citycodemap b on a.idcitycodemap=b.idcitycodemap where a.idcitycodemap=? order by idescortmanager,a.idcitycodemap";

@override

public escortmanager maprow(resultset rs,int rownum)throws sqlexception });

示例二:類屬類

string sql = "select a.idescortvehicle,a.platenumber from escortvehicle a "  ;

類屬類 @override

public escortvehicle maprow(resultset rs, int rownum) throws sqlexception

}

[1]關於timestamp型別

列出createtime欄位(timestamp型別)為今天的記錄

select * from cashbox where to_char(createtime,'yy/mm/dd') = to_char(sysdate,'yy/mm/dd')

其中to_char(sysdate,'yy/mm/dd')返回16/06/14.

timestamp型別比較示例

where = "and to_timestamp('"+begindate+"','yyyy-mm-dd') <= a.createtime ";

SpringJdbcTemplate 學習查詢小結

由於工作需要,資料互動層需要用jdbctemplate,於是學習了下,備忘 name springjdbctemplate what springjdbc封裝了繁瑣的jdbc直連 通過簡單的設定,在spring下更好的進行事務管理,它抽象出了一些我們常用的操作方法,使用起來簡單而高效。where 在...

Spring JdbcTemplate學習筆記示例

spring jdbctemplate使用方法 1,建表 create table admin 2,spring 配置 jdbc oracle thin root 123 localhost 1521 xe 3,使用方法 查詢多行查詢 public object maprow public list...

Spring JdbcTemplate 查詢分頁

現在進行的專案由於資料庫的遺留原因 設計的不堪入目 不能用hibernate.所以用的spring jdbctemplate,今天作派譴員工的分頁,發現乙個不錯的jdbctemplate分頁寫法,較現在搜尋到的寫法都值得說一說 看原始碼吧!很簡單 1.大家都有的page類 2.分頁的助手類 完了!下...