Statement和PrepareStatement有什么区别?

StatementPrepareStatement有什么区别?
(1)PrepareStatement中执行的SQL语句中是可以带参数的,而Statement则不可以。
(2)当处理批量SQL语句时,这个时候就可以体现PrepareStatement的优势,由于采用Cache机制,则预先编译的语句,就会
放在Cache中,下次执行相同SQL语句时,则可以直接从Cache中取出来。

调用存储过程,用CallableStatement

CallableStatement ps = null;
  try {
   con = commerceDao.getCurrentConnection();// orderDao.getConnection();
   // 调用存储过程,生成一个退货单code
   ps = con.prepareCall("{call SP_Order_GetOrderCode(?)}");
   ps.registerOutParameter(1, Types.VARCHAR);
   ps.execute();

   // 获得输出结果
   orderCode = ps.getString(1);

猜你喜欢

转载自xumiao900.iteye.com/blog/1714202