J2EE預覽:使用XML封裝JDBC語句設計

xml內容示例:
<sql id="001" comment="查詢學生信息"></sql>
    select * fom t_stu a
    where a.stu_id='{0}'
    and a.stu_name='{1}'

<sql id="002" comment="更新學生信息"></sql>
    update t_stu a
    set a.comment='學生{1}'||'學號:{0}'
    where set a.stu_id='{0}'


java 僞代碼:

String sql = sqlUtil.getSQLByID("001");
String comment = sqlUtil.getCommentByID("001");
sql.setParamMeterByName(0,"100");
sql.setParamMeterByName(1,"張三");

這時sql字符串的內容實際爲:
sql =   "select * fom t_stu a  where a.stu_id='100'  and a.stu_name='張三';

stmt.executesql(sql);
println(comment+"執行成功!");

 

發佈了1 篇原創文章 · 獲贊 0 · 訪問量 2850
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章