zoukankan      html  css  js  c++  java
  • 可变参数和preparestatement 结合使用

    public static void updat(String sql,Object...args) throws Exception{
    Connection connection=null;
    PreparedStatement preparedStatement=null;
    try {
    connection=getconnetion();
    preparedStatement=(PreparedStatement) connection.prepareStatement(sql);
    for(int i=0;i<args.length;i++){
    preparedStatement.setObject(i+1, args[i]);
    }
    preparedStatement.executeUpdate();
    } catch (ClassNotFoundException e) {

    e.printStackTrace();
    }

    }

    -----------------------------------------

    测试

    @Test
    public void test2(){
    Student student=new Student();
    String sql="insert into users values(?,?,?)";
    student.setId(5211314);
    student.setNameString("Myongyuan");
    student.setSconString("LaiShan");
    try {
    Tools.updat(sql, student.getId(),student.getNameString(),student.getSconString());
    } catch (Exception e) {

    e.printStackTrace();
    }
    }

  • 相关阅读:
    站立会议第七天
    站立会议第六天
    站立会议第五天
    站立会议第四天
    inotify简题
    搭建企业版yum仓
    ssh及ssh-key
    shell变量
    如何下载scp、wget、inotify及如何偷包
    rsync
  • 原文地址:https://www.cnblogs.com/afterhours/p/6108052.html
Copyright © 2011-2022 走看看