title: How to connect to POSTGRESQL database from a JSP page
body: <p>I am trying to connect to PostgreSQL database but this following code produces nothing on the page any help will be appreciated. </p>
  
  <p>This page is hosted in apache tomcat and a geoserver is already connected to the same database on the same machine and working fine.</p>
  
  <pre><code>&lt;%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.* " %&gt;
  &lt;%@ page import="java.io.*" %&gt;
  &lt;%
  try {
      String driver = "org.postgresql.Driver";
      String url = "jdbc:postgresql://localhost/mahaproperties";
      String username = "postgres";
      String password = "Apple123!@#";
      String myDataField = null;
      String myQuery = "select * from public.maharashtra_parcel LIMIT 1000";
      Connection myConnection = null;
      PreparedStatement myPreparedStatement = null;
      ResultSet myResultSet = null;
      Class.forName(driver).newInstance();
      myConnection = DriverManager.getConnection(url,username,password);
      System.out.println("Opened database successfully");
      myPreparedStatement = myConnection.prepareStatement(myQuery);
      ResultSet rs = myPreparedStatement.executeQuery();
  
      ResultSetMetaData rsmd = rs.getMetaData();
      int  totalColumn = rsmd.getColumnCount();
  
  
      out.println("&lt;table border='1' style='border-collapse:collapse'&gt;");
      out.println("&lt;tr&gt;");
  
      for(int i=1;i&lt;=totalColumn;i++)
      {
          String columnName = rsmd.getColumnName(i);
          out.println("&lt;th&gt;"+columnName+"&lt;/th&gt;");
      }
      out.println("&lt;/tr&gt;");
  
      while(rs.next())
      {    
          out.println("&lt;tr&gt;");
          for(int col=1;col&lt;=totalColumn;col++)
          {            
              Object obj= rs.getObject(col);                    
              out.println("&lt;td&gt;"+ String.valueOf(obj) +"&lt;/td&gt;");
          } 
          out.println("&lt;/tr&gt;");
      }
      out.println("&lt;/table&gt;");
  
  }
  catch(ClassNotFoundException e){
      e.printStackTrace();
  }
  catch (SQLException ex) {
      out.print("SQLException: "+ex.getMessage());
      out.print("SQLState: " + ex.getSQLState());
      out.print("VendorError: " + ex.getErrorCode());
  }
  %&gt;
  </code></pre>