title: Error while running JDBC on postgres
body: <p>This is my CreateQuery.java class .</p>
  
  <pre><code>package DbConnect;
  
  
  import java.io.FileNotFoundException;
  import java.io.IOException;
  import java.sql.Connection;
  import java.sql.PreparedStatement;
  import java.sql.ResultSet;
  import java.sql.SQLException;
  
  
      public class CreateQuery {
          Connection conn;
  
          public CreateQuery() throws ClassNotFoundException, SQLException, IOException {
              conn=new DbAccess().returnDatabaseConnection();
          }
          public int addNewLayertoDB(){
              try {
                  PreparedStatement statement = null;
                  //String table_name = feature_name + "_" + shape; 
  
                  String query = "SELECT the_geom from bbmp ";
                  statement = conn.prepareStatement(query);
                  //statement.setString(1, feature_name); 
                 ResultSet rs = statement.executeQuery();
                 rs.close();
                  return 1;
              } catch (SQLException ex) {
                  System.out.println("Sql exception");
                  return 0;
              }
          }
  
  
  
  
          public void closeConn() throws SQLException {
              if (conn != null) {
                  this.conn.close();
              }
          }
          public static void main(String args[]) throws FileNotFoundException, IOException, ClassNotFoundException, SQLException{
              CreateQuery cq = new CreateQuery();
              cq.addNewLayertoDB();
              cq.closeConn();
  
          }
      }
  </code></pre>
  
  <p>This is my DbConnect class </p>
  
  <pre><code>package DbConnect;
  
  
  
  import java.sql.DriverManager;
  import java.sql.Connection;
  import java.sql.SQLException;
  
  public class DbAccess{
  
      public static void main(String[] argv) {
  
          System.out.println("-------- PostgreSQL " +
                  "JDBC Connection Testing ------------");
  
          try {
  
              Class.forName("org.postgresql.Driver");
  
          } catch (ClassNotFoundException e) {
  
              System.out.println("Where is your PostgreSQL JDBC Driver? " +
                      "Include in your library path!");
              e.printStackTrace();
              return;
  
              }
  
          System.out.println("PostgreSQL JDBC Driver Registered!");
  
          Connection connection = null;
  
          try {
  
              connection = DriverManager.getConnection(
                  "jdbc:postgresql://127.0.0.1:5432/Ethermap","postgres", "*******");
  
          } catch (SQLException e) {
  
              System.out.println("Connection Failed! Check output console");
              e.printStackTrace();
              return;
  
          }
  
          if (connection != null){
              System.out.println("You made it, take control your database now!");
          }else{
              System.out.println("Failed to make connection!");
          }
      }
  
      public Connection returnDatabaseConnection() {
          System.out.println("DB not connected");
          return null;
      }
  
  }
  </code></pre>
  
  <p>The error I am getting when I run CreateQuery is </p>
  
  <pre><code>DB not connected
  Exception in thread "main" java.lang.NullPointerException
      at DbConnect.CreateQuery.addNewLayertoDB(CreateQuery.java:24)
      at DbConnect.CreateQuery.main(CreateQuery.java:45)
  </code></pre>
  
  <p>What is the error ? And How do I debug it ?</p>