Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8619063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:15:19+00:00 2026-06-12T06:15:19+00:00

i have the following program which goes to database and gets the value, i

  • 0

i have the following program which goes to database and gets the value, i have excuted the query also it gives me only 47 row but when i run the same program in console mode it gives me Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

package com.common;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Timestamp;
import java.sql.Types;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

import com.common.Query;

public class GetColumnValuesFromDifferentTypes {
@SuppressWarnings("unused")
public static void printColumns(String query){
    ABIDAO abidao = new ABIDAO();
    int numberOfColumns=0,columnType = 0;
    String columnValue = "", columnName = "";
    Map<String, String> headerMap = new LinkedHashMap<String, String>();
        Connection connection = abidao.getConnection();
        if (connection != null) {
            try {
                headerMap = getHeader(query);
                System.out.println("====================================================================");
                System.out.println("Header Map : "+headerMap);
                System.out.println("====================================================================");
                PreparedStatement reportTablePS = connection.prepareStatement(query);
                ResultSet reportTable_rst = reportTablePS.executeQuery();
                ResultSetMetaData reportTable_rsmd = reportTable_rst.getMetaData();
                numberOfColumns = reportTable_rsmd.getColumnCount();

                    int i =0;
                    while (reportTable_rst.next()) {
                            for (int columnIterator = 1; columnIterator <= numberOfColumns; columnIterator++) {
                                 columnValue = null;
                               columnName = reportTable_rsmd.getColumnName(columnIterator);
                               columnType = reportTable_rsmd.getColumnType(columnIterator);

                               if(columnType == Types.CHAR || columnType == Types.VARCHAR || columnType == Types.LONGVARCHAR)
                               {
                                   columnValue = reportTable_rst.getString(columnName);
                               }else if(columnType == Types.INTEGER || columnType == Types.BIGINT || columnType == Types.SMALLINT || columnType == Types.NUMERIC)
                               {
                                   long templong = reportTable_rst.getLong(columnName);
                                   if(!reportTable_rst.wasNull())
                                   {
                                       columnValue  = Long.toString(templong);
                                   }
                               }else if(columnType == Types.DECIMAL || columnType == Types.DOUBLE || columnType == Types.FLOAT || columnType == Types.REAL)
                               {
                                   double tempDouble1 = reportTable_rst.getDouble(columnName);
                                   if(!reportTable_rst.wasNull())
                                   {
                                       columnValue  = Double.toString(tempDouble1);
                                   }
                               } else if(columnType == Types.TIME || columnType == Types.TIMESTAMP || columnType == Types.DATE)
                               {
                                   Timestamp sqlTimeStamp = reportTable_rst.getTimestamp(columnName);
                                   if(!reportTable_rst.wasNull())
                                   {
                                       columnValue = sqlTimeStamp.toString();
                                   }
                               }
                               System.out.println("columnValue : "+columnValue);
                               System.out.println(",");

                            }
                            System.out.println("====================================================================");
                        }
            } catch (Exception ex) {
                ex.printStackTrace();
            }finally {
                try {
                    abidao.closeConnection(connection, null, null);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        }
}
@SuppressWarnings({ "unused" })
public static  Map<String, String> getHeader(String query) {
    ABIDAO abidao = new ABIDAO();
    String columnName="";
    int numberOfColumns=0,rowCount=1;
    Map<String, String> headerNamesMap = new LinkedHashMap<String, String>();
    Connection connection = abidao.getConnection();
    if (connection != null) {
        try {
            PreparedStatement reportTablePS = connection.prepareStatement(query);
            ResultSet reportTable_rst = reportTablePS.executeQuery();
            ResultSetMetaData rsmd = reportTable_rst.getMetaData();
            numberOfColumns = rsmd.getColumnCount();
            headerNamesMap.put("SNO","SNO");
              while (reportTable_rst.next()) {
                for (int i = 1; i <= numberOfColumns; i++) {
                  columnName = rsmd.getColumnName(i).toUpperCase();
                  if(!headerNamesMap.containsKey(columnName)){
                      headerNamesMap.put(columnName, columnName); 
                  }
                }
                rowCount++;
              }

        } catch (Exception ex) {
            ex.printStackTrace();
        }finally {
            try {
                abidao.closeConnection(connection, null, null);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }
    return headerNamesMap;
}
@SuppressWarnings("rawtypes")
public static void main(String[] args) {
    String query = "";
    Map dynamicQueryMap = new HashMap();
    Query queryObj = new Query();

    try {
        dynamicQueryMap = queryObj.getComplexReportQuery();
        if(dynamicQueryMap.containsKey("query")) query = dynamicQueryMap.get("query").toString();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    printColumns(query);

}
}

This is the query which is return from the Query method :

select
pi.po_number,poi.unit_cost,pi.placed_date CreateDate,
case when isnull(pi.date_closed) then pi.scheduled_arrival_date  
else pi.date_closed end as ReceviedDate,
poi.order_quantity,poi.roll_number,p.product_sku product_name,
pc.product_category_name,poi.rec_vendor_quantity,pv.vendor_name,p.et_conversion_unit_quantity,pi.note
from
purchase_order as pi,
purchase_order_inventory as poi,
product_vendors as pv,
products AS p,
product_categories AS pc
where
pi.purchase_order_id=poi.purchase_order_id and
pc.product_category_id=p.product_category_id and
poi.product_id = p.product_id and
poi.product_category_id=pc.product_category_id and
pi.vendor_id=pv.product_vendor_id and
( ( pi.date_closed  >= '2012-01-01' and pi.date_closed <='2012-09-05 23:59:59' ) 
or ( pi.scheduled_arrival_date  >= '2012-01-01' and pi.scheduled_arrival_date <='2012-09-05 23:59:59') ) and
pi.po_type=0 
and pi.status_id = 0 and  poi.transaction_type = 0  
order by pi.po_number ;

what is the problem here i am facing!! please help me to find it out.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T06:15:21+00:00Added an answer on June 12, 2026 at 6:15 am

    You need to close all your resources, not just the connection. e.g. PreparedStatement.close() and ResultSet.close() If you don’t do this they are retained and become a form of a memory leak.

    I suggest you confirm this yourself using jmap -histo:live {pid} or using a memory profiler like VisualVM or YourKit.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this following program which gets the number of files from user, then
I have the following c program which launches a Gtk Program on ubuntu: #include
I have a following program but for some reason it is throwing an error
I have the following program which I'd like to get it fixed. Not sure
I am cross compiling linux kernel. I have the following program which compiles perfectly
I have done up a program which requires the following: prompts user input account
I have the following assembly program which displays the letter 'z' and then exits:
I have following program in which I am adding few number to set and
I have the following C99 program which measures performance of simple division operations relative
I have the following Java Program which one starts in about 50% of all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.