Class DBConnection

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    public class DBConnection
    extends java.lang.Object
    implements java.lang.AutoCloseable
    Author:
    Collin Alpert
    See Also:
    GitHub
    • Constructor Summary

      Constructors 
      Constructor Description
      DBConnection()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes the connection to the database.
      java.sql.ResultSet execute​(java.lang.String query)
      Executes an SELECT SQL statement on the database without Java parameters.
      java.sql.ResultSet execute​(java.lang.String query, java.lang.Object... params)
      Executes an SELECT SQL statement on the database with Java parameters.
      boolean isOpen()
      Determines if a connection to the database still exists or not.
      boolean isValid()
      Checks if the connection is valid/successful.
      boolean update​(java.lang.String query)
      This command is used for any queries that are supposed to update the database, such as UPDATE, DELETE, TRUNCATE etc.
      boolean update​(java.lang.String query, java.lang.Object... params)
      This command is used for any queries that are supposed to update the database, such as UPDATE, DELETE, TRUNCATE etc.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DBConnection

        public DBConnection()
    • Method Detail

      • isValid

        public boolean isValid()
        Checks if the connection is valid/successful.
        Returns:
        True if connection was successful, false if not.
      • execute

        public java.sql.ResultSet execute​(java.lang.String query)
        Executes an SELECT SQL statement on the database without Java parameters.
        Parameters:
        query - The query to be executed.
        Returns:
        The ResultSet containing the result from the SELECT query.
      • execute

        public java.sql.ResultSet execute​(java.lang.String query,
                                          java.lang.Object... params)
        Executes an SELECT SQL statement on the database with Java parameters.
        Parameters:
        query - The query to be executed.
        params - The Java parameters to be inserted into the query.
        Returns:
        The ResultSet containing the result from the SELECT query.
      • update

        public boolean update​(java.lang.String query)
        This command is used for any queries that are supposed to update the database, such as UPDATE, DELETE, TRUNCATE etc.
        Parameters:
        query - The query to be executed.
        Returns:
        True if the update was successful, false if not.
      • update

        public boolean update​(java.lang.String query,
                              java.lang.Object... params)
        This command is used for any queries that are supposed to update the database, such as UPDATE, DELETE, TRUNCATE etc.
        Parameters:
        query - The query to be executed.
        params - The Java parameters to be inserted into the query.
        Returns:
        True if the update was successful, false if not.
      • isOpen

        public boolean isOpen()
        Determines if a connection to the database still exists or not.
        Returns:
        True if a connection exists, false if not. This method will return false if an exception occurs.
      • close

        public void close()
        Closes the connection to the database.
        Specified by:
        close in interface java.lang.AutoCloseable