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();
    }
    }

  • 相关阅读:
    C语言I博客作业06
    C语言I博客作业05
    C语言I博客作业04
    C语言I博客作业03
    C语言I博客作业02
    第一次作业
    C语言I博客作业09
    C语言I博客作业08
    C语言I博客作业07
    C语言I博客作业06
  • 原文地址:https://www.cnblogs.com/afterhours/p/6108052.html
Copyright © 2011-2022 走看看