public JobIniciado retornaUltimoLote(Connection conn, String job, int operacao) throws SQLException { String sql = " select job, operacao, tripulacao,recurso, max(data_fim) \n" + "from joblote where job = ? and operacao = ? \n" + "group by job, operacao, tripulacao, recurso "; PreparedStatement stmt = null; ResultSet rs = null; JobIniciado iniciado = null; stmt = conn.prepareStatement(sql); stmt.setString(1, job.trim().replace(".", "")); stmt.setInt(2, operacao); rs = stmt.executeQuery(); if (rs.next()) { iniciado = new JobIniciado(); iniciado.setJob(rs.getString(1)); iniciado.setOperacao(rs.getInt(2)); iniciado.setTripulacao(rs.getDouble(3)); iniciado.setRecurso(rs.getString(4)); Timestamp data = rs.getTimestamp(5); iniciado.setData(Validacoes.getDataHoraString(data)); } return iniciado; }
public ArrayList<File> getFiles(String sql) { ArrayList<File> list = new ArrayList<File>(); Connection conn = null; ResultSet rs = null; PreparedStatement ps = null; try { conn = getConnection(); ps = conn.prepareStatement( sql.toLowerCase().startsWith("select") ? sql : ("SELECT FILENAME, MODIFIED FROM FILES WHERE " + sql)); rs = ps.executeQuery(); while (rs.next()) { String filename = rs.getString("FILENAME"); long modified = rs.getTimestamp("MODIFIED").getTime(); File file = new File(filename); if (file.exists() && file.lastModified() == modified) { list.add(file); } } } catch (SQLException se) { LOGGER.error(null, se); return null; } finally { close(rs); close(ps); close(conn); } return list; }
public static Show[] getShows() { Logger.log("Database.getShows", CALL_FLAG); Show[] shows = new Show[0]; try { Hall[] halls = getHalls(); Movie[] movies = getMovies(); Timestamp time; Hall hall; Movie movie; int ID; ResultSet rs = query("SELECT COUNT(*) FROM forestillinger"); rs.next(); shows = new Show[rs.getInt("COUNT(*)")]; rs = query("SELECT * FROM forestillinger ORDER BY tid ASC"); while (rs.next()) { hall = halls[rs.getInt("sal_id") - 1]; movie = movies[rs.getInt("film_id") - 1]; time = rs.getTimestamp("tid"); ID = rs.getInt("forestilling_id"); shows[rs.getRow() - 1] = new Show(hall, movie, time, ID); } } catch (Exception exception) { Logger.log(exception, "Database:getShows"); } Logger.log("Database.getShows", FINISHED_FLAG); return shows; }
public void cleanup() { Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; try { conn = getConnection(); ps = conn.prepareStatement("SELECT COUNT(*) FROM FILES"); rs = ps.executeQuery(); dbCount = 0; if (rs.next()) { dbCount = rs.getInt(1); } rs.close(); ps.close(); PMS.get().getFrame().setStatusLine(Messages.getString("DLNAMediaDatabase.2") + " 0%"); int i = 0; int oldpercent = 0; if (dbCount > 0) { ps = conn.prepareStatement( "SELECT FILENAME, MODIFIED, ID FROM FILES", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE); rs = ps.executeQuery(); while (rs.next()) { String filename = rs.getString("FILENAME"); long modified = rs.getTimestamp("MODIFIED").getTime(); File file = new File(filename); if (!file.exists() || file.lastModified() != modified) { rs.deleteRow(); } i++; int newpercent = i * 100 / dbCount; if (newpercent > oldpercent) { PMS.get() .getFrame() .setStatusLine(Messages.getString("DLNAMediaDatabase.2") + newpercent + "%"); oldpercent = newpercent; } } } } catch (SQLException se) { LOGGER.error(null, se); } finally { close(rs); close(ps); close(conn); } }