franta-hg@16: package cz.frantovo.sql.vyuka.dao; franta-hg@16: franta-hg@29: import java.sql.Connection; franta-hg@29: import java.sql.PreparedStatement; franta-hg@29: import java.sql.ResultSet; franta-hg@29: import java.util.logging.Level; franta-hg@29: franta-hg@16: /** franta-hg@29: * Rady, tipy, odkazy, citáty… pro zobrazování uživatelům. franta-hg@16: * @author fiki franta-hg@16: */ franta-hg@16: public class TipyDAO extends VyukaSuperDAO { franta-hg@16: franta-hg@29: private enum SQL { franta-hg@29: franta-hg@29: NAHODNY_TIP franta-hg@29: } franta-hg@29: franta-hg@29: /** franta-hg@29: * @return Náhodný tip načtený z databáze franta-hg@29: */ franta-hg@16: public String getTip() { franta-hg@29: Connection db = getSpojeni(DATABAZE.APLIKACE); franta-hg@29: if (db == null) { franta-hg@29: log.log(Level.SEVERE, "Databáze je null."); franta-hg@29: return null; franta-hg@29: } else { franta-hg@29: PreparedStatement ps = null; franta-hg@29: ResultSet rs = null; franta-hg@29: try { franta-hg@29: ps = db.prepareStatement(getSQL(SQL.NAHODNY_TIP)); franta-hg@29: rs = ps.executeQuery(); franta-hg@29: rs.next(); franta-hg@29: return rs.getString("text"); franta-hg@29: } catch (Exception e) { franta-hg@29: log.log(Level.SEVERE, "Chyba při hledání náhodného tipu.", e); franta-hg@29: return null; franta-hg@29: } finally { franta-hg@29: zavri(db, ps, rs); franta-hg@29: } franta-hg@29: } franta-hg@16: } franta-hg@16: }