public <E> E getValue(Connection conn, String sql, Object...args) { PreparedStatement ps = null; ResultSet resultSet = null; try { ps = conn.prepareStatement(sql); for (int i = 0; i < args.length; i++) { ps.setObject((i+1), args[i]); } resultSet = ps.executeQuery(); if (resultSet.next()) { return (E) resultSet.getObject(1); } } catch (SQLException e) { e.printStackTrace(); } finally { JDBCUtils.closeResource(null, ps, resultSet); } return null; }
查询特殊值的操作
可以用这个来查询数据库中满足某条件的数据个数等等