java.sql.connection對象

preparedstatement

是從java.sql.connection對象和所提供的sql字符串得到的,sql字符串中包含問號(?),這些問號標明變量的位置,然後提供變量的值,最後執行語句,例如: 

string sql = "select * from people p where p.id = ? and p.name = ?";
preparedstatement ps = connection.preparestatement(sql);
ps.setint(1,id);
ps.setstring(2,name);
resultset rs = ps.executequery(); 

使用preparedstatement的另一個優點是字符串不是動態創建的。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章