import java.sql.*; public class QueryBean { Connection cn = null; ResultSet rs = null; boolean ownConnection = true; public void setConnection(Connection conn) { cn = conn; ownConnection = false; } public void setQuery(String sql) { try { if (cn == null) cn = Examples.getConnection(); rs = cn.createStatement().executeQuery(sql); } catch (SQLException s) { /* Ignore */ } } public boolean next() { try { return (rs != null) ? rs.next() : false; } catch (SQLException s) { return false; } } public String column(int colNumber) { try { return (rs != null) ? rs.getString(colNumber) : ""; } catch (SQLException s) { return ""; }; } public void close() { try { rs.close(); if (ownConnection) cn.close();} catch (Exception e) { /* Ignore */ } } } |