java实现简单的给sql语句赋值的示例_java

分享到:

代码本身很简单。拼接sql的时候?不好数,简单的用来赋值。


/**
  * TODO 循环赋值,缺少的类型可随时添加
  * @author Lucius
  * @param pt
  * @param list
  * @throws SQLException
  */
 public static void setParam(PreparedStatement pt, List list) throws SQLException{
  for(int i = 0;i<list.size();i++){
   if (list.get(i) instanceof String) pt.setString(i+1, list.get(i).toString());
   else if(list.get(i) instanceof Integer) pt.setInt(i+1, Integer.parseInt(list.get(i).toString()));
   else if(list.get(i) instanceof Short)pt.setShort(i+1, Short.parseShort(list.get(i).toString()));
   else pt.setObject(i+1, list.get(i));
  }
 }

昵    称:
验证码:

相关文档: