Package adams.db

Interface SQLIntf

    • Method Detail

      • setDebug

        void setDebug​(boolean value)
        Sets whether debugging is enabled, outputs more on the console.
        Parameters:
        value - if true debugging is enabled
      • getDebug

        boolean getDebug()
        Returns whether debugging is enabled.
        Returns:
        true if debugging is enabled
      • tableExists

        boolean tableExists​(String table)
        Checks that a given table exists.
        Parameters:
        table - the table to look for
        Returns:
        true if the table exists.
      • columnExists

        boolean columnExists​(String table,
                             String column)
        Checks that a given column exists.
        Parameters:
        table - the table to search
        column - the column to look for
        Returns:
        true if the column exists.
      • getSimpleResultSet

        SimpleResultSet getSimpleResultSet​(String query)
                                    throws Exception
        Execute the given SQL statement and return ResultSet.
        Parameters:
        query - SQL query String
        Returns:
        resulting ResultSet, or null if Error
        Throws:
        Exception - if something goes wrong
      • prepareStatement

        PreparedStatement prepareStatement​(String query)
                                    throws Exception
        Create a Prepared statement with given query.
        Parameters:
        query - the query to execute
        Returns:
        PreparedStatement
        Throws:
        Exception - if something goes wrong
      • prepareStatement

        PreparedStatement prepareStatement​(String query,
                                           boolean returnKeys)
                                    throws Exception
        Create a Prepared statement with given query.
        Parameters:
        query - the query to execute
        returnKeys - whether to initialize the statement that it returns the generated keys
        Returns:
        PreparedStatement
        Throws:
        Exception - if something goes wrong
      • prepareStatement

        PreparedStatement prepareStatement​(Connection conn,
                                           String query,
                                           boolean returnKeys)
                                    throws Exception
        Create a Prepared statement with given query.
        Parameters:
        conn - the database connection to use
        query - the query to execute
        returnKeys - whether to initialize the statement that it returns the generated keys
        Returns:
        PreparedStatement
        Throws:
        Exception - if something goes wrong
      • update

        int update​(String updateString,
                   String table,
                   String where)
            throws Exception
        Update table.
        Parameters:
        updateString - comma separated updates. e.g weight='80',height=180
        table - the table to update
        where - condition. e.g name='bob smith'
        Returns:
        number of rows affected
        Throws:
        Exception - if something goes wrong
      • executeGeneratedKeys

        ResultSet executeGeneratedKeys​(String query)
                                throws Exception
        Executes a SQL query. Return any Generated Keys Caller is responsible for closing the statement.
        Parameters:
        query - the SQL query
        Returns:
        Generated keys as a resultset, or null if failure
        Throws:
        Exception - if something goes wrong
      • execute

        Boolean execute​(String query)
                 throws Exception
        Executes a SQL query.
        Parameters:
        query - the SQL query
        Returns:
        true if the query generated results, false if it didn't, null in case of an error
        Throws:
        Exception - if an error occurs
      • truncate

        boolean truncate​(String table)
        Empty table.
        Parameters:
        table - the table to empty
        Returns:
        success?
      • drop

        boolean drop​(String table)
        Drops the table.
        Parameters:
        table - the table to empty
        Returns:
        success?
      • select

        ResultSet select​(String columns,
                         String tables,
                         String where)
                  throws Exception
        Do a select on given columns for all data in joined tables, with condition.
        Parameters:
        columns - columns to select
        tables - the tables to select from
        where - condition
        Returns:
        resultset of data
        Throws:
        Exception - if something goes wrong
      • selectDistinct

        ResultSet selectDistinct​(String columns,
                                 String tables,
                                 String where)
                          throws Exception
        Do a select distinct on given columns for all data in joined tables, with condition.
        Parameters:
        columns - columns to select
        tables - the tables to select from
        where - condition
        Returns:
        resultset of data
        Throws:
        Exception - if something goes wrong
      • selectString

        List<String> selectString​(boolean distinct,
                                  String column,
                                  String tables,
                                  String where)
                           throws Exception
        Selects all strings from the specified column. Can be distinct.
        Parameters:
        distinct - whether values in column have to be distinct
        column - the string column to select
        tables - the tables to select from, ignored if null
        where - condition, can be null
        Returns:
        resultset of data
        Throws:
        Exception - if something goes wrong
      • selectStrings

        List<String[]> selectStrings​(boolean distinct,
                                     String[] columns,
                                     String tables,
                                     String where)
                              throws Exception
        Selects all strings from the specified columns. Can be distinct (uses a CONCAT internally for that).
        Parameters:
        distinct - whether values in column have to be distinct
        columns - the string columns to select
        tables - the tables to select from, ignored if null
        where - condition, can be null
        Returns:
        resultset of data
        Throws:
        Exception - if something goes wrong
      • selectInt

        gnu.trove.list.TIntList selectInt​(boolean distinct,
                                          String column,
                                          String tables,
                                          String where)
                                   throws Exception
        Selects all integers from the specified column. Can be distinct.
        Parameters:
        distinct - whether values in column have to be distinct
        column - the int column to select
        tables - the tables to select from, ignored if null
        where - condition, can be null
        Returns:
        resultset of data
        Throws:
        Exception - if something goes wrong
      • selectLong

        gnu.trove.list.TLongList selectLong​(boolean distinct,
                                            String column,
                                            String tables,
                                            String where)
                                     throws Exception
        Selects all longs from the specified column. Can be distinct.
        Parameters:
        distinct - whether values in column have to be distinct
        column - the long column to select
        tables - the tables to select from, ignored if null
        where - condition, can be null
        Returns:
        resultset of data
        Throws:
        Exception - if something goes wrong
      • selectDouble

        gnu.trove.list.TDoubleList selectDouble​(boolean distinct,
                                                String column,
                                                String tables,
                                                String where)
                                         throws Exception
        Selects all doubles from the specified column. Can be distinct.
        Parameters:
        distinct - whether values in column have to be distinct
        column - the long column to select
        tables - the tables to select from, ignored if null
        where - condition, can be null
        Returns:
        resultset of data
        Throws:
        Exception - if something goes wrong
      • getResultSet

        ResultSet getResultSet​(String query)
                        throws Exception
        Return resultset of given query.
        Parameters:
        query - sql query
        Returns:
        resulset
        Throws:
        Exception - if something goes wrong
      • getMaxColumnNameLength

        int getMaxColumnNameLength()
                            throws SQLException
        Returns the maximum length for column names. In case the meta-data returns 0, Integer.MAX_VALUE is used instead.
        Returns:
        the maximum length
        Throws:
        SQLException - if the query fails