Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用QueryRunner类删除记录_Java_Jsp_Jstl - Fatal编程技术网

Java 如何使用QueryRunner类删除记录

Java 如何使用QueryRunner类删除记录,java,jsp,jstl,Java,Jsp,Jstl,如何使用QueryRunner类从mysql数据库中删除记录?ID作为字符串数组传递。另外,您是否可以建议在DML操作中使用apache common db UTIL是否良好,以及有哪些替代方案或最佳实践 下面是我的StudentDAO.java类的摘录 public boolean deleteStudent(String [] ids) { Connection connection = null; String qu

如何使用QueryRunner类从mysql数据库中删除记录?ID作为字符串数组传递。另外,您是否可以建议在DML操作中使用apache common db UTIL是否良好,以及有哪些替代方案或最佳实践

下面是我的StudentDAO.java类的摘录

            public boolean deleteStudent(String [] ids) {

            Connection connection = null;
            String query;
            boolean result = false;

            try {
                Context initCtx = new InitialContext();
                Context envCtx = (Context) initCtx.lookup("java:comp/env");
                DataSource ds = (DataSource) envCtx.lookup("jdbc/cmsDB");
                connection = ds.getConnection();

                QueryRunner run = new QueryRunner(ds);
                query = "delete tbl_student where student_id";// what should i put here???
                int nor = run.update(query, ids); //nor = no of records

                if (nor > 0) {
                    result = true;
                } else {
                    result = false;
                }
            } catch (NumberFormatException e) {
                // e.getMessage();
                e.printStackTrace();
            } catch (SQLException e) {
                e.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                DbUtils.closeQuietly(connection);
            }
            return result;
        }
公共静态字符串联接(字符串[]s,字符串分隔符){
int imax=s.长度;
字符串strJoin=“”;
如果(imax>1){
int i=0;
对于(i=0;i
public static String join(String[] s, String delimiter) {
    int imax = s.length;
    String strJoin="";
    if (imax > 1) {
        int i = 0;
        for (i = 0; i < imax-1; i++) {
            strJoin += s[i] + delimiter;

        }
        strJoin += s[i];            
    }
    else
        strJoin += s[0];
    return strJoin;
}

public boolean deleteStudent(String [] ids) {
    ...
    ...
    ...
    query = "delete tbl_student where student_id in ("+ join(ids,",") +")";
    ...
    ...
    ...
]