title: How we can implement Cucumber test for database testing
body: <p>I am trying to configure Cucumber test for database testing since my application have some rest services and I need to check the database in order to verify the records are updated with proper value.</p>
  
  <p>I am using Postgres database. I have a feature file listed as below:</p>
  
  <pre><code>Feature: API Test
  
  Background: Given I am connected with the database
  
  Scenario: I want to test the database connection        
  When I run the select query         
  Then I should see the result as "Pranjal"
  </code></pre>
  
  <p>Database Connection class is as follows:</p>
  
  <p>public class DatabaseConnection {</p>
  
  <pre><code>public DatabaseConnection createConnection() throws Exception {
  
      try {
          //Connection URL Syntax: "jdbc:postgresql://ipaddress:portnumber/db_name"       
          String dbUrl = "jdbc:postgresql://localhost:5432/test";                 
  
          //Database User name
          String username = "postgres";   
  
          //Database Password
          String password = "12345678";
  
          //Query to Execute      
          String query = "select * from test where no = 1;";
  
          //Load PostgreSQL JDBC driver       
          Class.forName("org.postgresql.Driver");         
  
          //Create Connection to DB       
          Connection con = DriverManager.getConnection(dbUrl,username,password);
  
          //Create Statement Object       
          Statement stmt = con.createStatement();                 
  
          // Execute the SQL Query. Store results in ResultSet        
          ResultSet rs = stmt.executeQuery(query);                            
  
          // While Loop to iterate through all data and print results     
          while (rs.next()){
              String myName = rs.getString(1);                                                                                           
              System.out.println(myName);     
          }       
  
          // closing DB Connection        
          con.close();
      } catch(SQLException e) {
        e.printStackTrace();
      }
  
      return new DatabaseConnection();            
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I have a Runner Class which will going to execute my feature file.</p>
  
  <p>I want my steps to execute the query and database connection is created as a Background condition..</p>
  
  <p>Is there a way to achieve this?</p>