Class Db


  • public class Db
    extends java.lang.Object
    A simple wrapper around the JDBC API. Currently used for testing. Features:
    • No checked exceptions
    • Easy to use, fluent API
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Db.Prepared
      This class represents a prepared statement.
    • Constructor Summary

      Constructors 
      Constructor Description
      Db​(java.sql.Connection conn)
      Create a database object using the given connection.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Close the database connection.
      void commit()
      Commit a pending transaction.
      void execute​(java.lang.String sql)
      Execute a SQL statement.
      Db.Prepared prepare​(java.lang.String sql)
      Prepare a SQL statement.
      java.util.List<java.util.Map<java.lang.String,​java.lang.Object>> query​(java.lang.String sql)
      Execute a SQL statement.
      void setAutoCommit​(boolean autoCommit)  
      • Methods inherited from class java.lang.Object

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

      • Db

        public Db​(java.sql.Connection conn)
        Create a database object using the given connection.
        Parameters:
        conn - the database connection
    • Method Detail

      • prepare

        public Db.Prepared prepare​(java.lang.String sql)
        Prepare a SQL statement.
        Parameters:
        sql - the SQL statement
        Returns:
        the prepared statement
      • execute

        public void execute​(java.lang.String sql)
        Execute a SQL statement.
        Parameters:
        sql - the SQL statement
      • query

        public java.util.List<java.util.Map<java.lang.String,​java.lang.Object>> query​(java.lang.String sql)
        Execute a SQL statement.
        Parameters:
        sql - the SQL statement
        Returns:
        a list of maps
      • close

        public void close()
        Close the database connection.
      • setAutoCommit

        public void setAutoCommit​(boolean autoCommit)
      • commit

        public void commit()
        Commit a pending transaction.