ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   To Refer this Site to Your Friends   Click Here
Google
 
Categories  >>  Code Snippets  >>  Scripts_Markup Code  >>  JavaScript Code
 
 


 

 
 PHP Code interview questions  PHP Code Interview Questions
 JSP Code interview questions  JSP Code Interview Questions
 ASP Code interview questions  ASP Code Interview Questions
 CGI Perl Code interview questions  CGI Perl Code Interview Questions
 JavaScript Code interview questions  JavaScript Code Interview Questions
 VB Script Code interview questions  VB Script Code Interview Questions
 Shell Script Code interview questions  Shell Script Code Interview Questions
 Python Code interview questions  Python Code Interview Questions
 WinRunner Code interview questions  WinRunner Code Interview Questions
 HTML DHTML XHTML Code interview questions  HTML DHTML XHTML Code Interview Questions
 XML interview questions  XML Interview Questions
 Scripts_Markup Code AllOther interview questions  Scripts_Markup Code AllOther Interview Questions
Question
Exception in thread "main" java.lang.OutOfMemoryError: Java
heap space:
 Question Submitted By :: Laxmanit08
I also faced this Question!!     Rank Answer Posted By  
 
  Re: Exception in thread "main" java.lang.OutOfMemoryError: Java heap space:
Answer
# 1
hi friends wht is my task is data is transfered one
db.tables to another db.tables
in tht i write a query check the backup compare to live wht
ever new rows tht will be inserted into backup in tht min of
data means it's wrkg .heavy data means it's not wrkg tell me
the reason how to solve this problem plzzzzzzzz


import java.util.*;
import java.sql.*;

import javax.sql.*;

public class connection 
{
	public static void main(String[] args) 
	{		
		try
		{
            Class.forName("com.mysql.jdbc.Driver");     
            Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/testback","root","root");
    
            Statement stmt=con.createStatement();
           
            String payment_date=null;
            String payment_ids=null;
            ResultSet rs=stmt.executeQuery("select
payment_id,payment_date from care_billing_payment order by
payment_id desc limit 1");
            if(rs.next())
            {
            	 payment_date= rs.getString("payment_date");
            	 payment_ids= rs.getString("payment_id");
            }
            System.out.println(payment_date);
            System.out.println(payment_ids);
            
            con.close();
            Vector v = new Vector();
            
            if(payment_date!=null && payment_ids!=null)
            {
            	 System.out.println("Live Database");
            	 
            	 Connection con1 =
DriverManager.getConnection("jdbc:mysql://localhost:3306/testlive","root","root");
                 
            	 Statement stmt1=con1.createStatement();
              	 String sql1 = "SELECT
payment_id,payment_encounter_nr,payment_date,status,final_settlement
FROM care_billing_payment where payment_id >
'"+payment_ids+"'  order by payment_id asc";
              	 ResultSet rs1=stmt1.executeQuery(sql1);
              	 
              	 while(rs1.next())
              	 {
              		 Hashtable h = new Hashtable();
              		 
              		 long payment_id= rs1.getLong("payment_id");
              		 System.out.println(payment_id);
              		 String payment_id1 =
String.valueOf(payment_id);
              		 long payment_encounter_nr =
rs1.getLong("payment_encounter_nr");
              		 System.out.println(payment_encounter_nr);
              		 String number =
String.valueOf(payment_encounter_nr);
              		 
              		 h.put("payment_id",payment_id1);
                  	 h.put("payment_encounter_nr",number) ;
                  	
h.put("payment_date",(String)rs1.getString("payment_date"));
                  	
h.put("status",(String)rs1.getString("status"));
                  	
h.put("settlement",(String)rs1.getString("final_settlement"));
                  	//
h.put("payment_cash_amount",rs1.getString("payment_cash_amount"));
                  	 // h.put("payment_receipt_nr",number1) ;
                  	 v.addElement(h);
              	 }
              	con1.close();
            }
              
              
              
            Connection con2 =
DriverManager.getConnection("jdbc:mysql://localhost:3306/testback","root","root");
    //Connect to demobilldb Data source
            System.out.println("BackUp Database");
              
            for(int i=0;i<v.size();i++)
            {
                  Hashtable h1 = (Hashtable)v.elementAt(i);
                  
                  String payment_id =
(String)h1.get("payment_id");
                  long payment_id1 =Long.parseLong(payment_id);
                  String encounter_nr =
(String)h1.get("payment_encounter_nr");
                  long encounter_nr1
=Long.parseLong(encounter_nr);
                  String status = (String)h1.get("status");
                  String settlement =
(String)h1.get("settlement");
                  String date = (String)h1.get("payment_date");
                
                 //String amount =
(String)h1.get("payment_cash_amount");
                 
                 //String receipt_nr =
(String)h1.get("payment_receipt_nr");
                // long receipt_nr1 =Long.parseLong(receipt_nr);
                 
                  String sql2="select time_id from calendar
where the_date='"+date+"';";
                  Statement stmt2=con2.createStatement();;
                  ResultSet rs2 = stmt2.executeQuery(sql2);
                  int time_id=0;
                  if(rs2.next())
                	  time_id=rs2.getInt(1);
                 
                 PreparedStatement prpStmt =
con2.prepareStatement("insert into care_billing_payment
(payment_id,payment_encounter_nr,status,final_settlement,payment_date,time_id)
values(?,?,?,?,?,?)");
                  
                 prpStmt.setLong(1,payment_id1);
                 prpStmt.setLong(2,encounter_nr1);
                 prpStmt.setString(3,status);
                 prpStmt.setString(4,settlement);
                 prpStmt.setString(5,date);
                 prpStmt.setInt(6,time_id);
                 
                  //  prpStmt.setString(6,receipt_nr1);
                 
                  
                  prpStmt.executeUpdate();
                  
                  if(status.equals("paid") &&
settlement.equals("4"))
                  {
                                              
                	  prpStmt = con2.prepareStatement("update
care_billing_payment set status=? where
payment_encounter_nr=?");
                	  prpStmt.setString(1,status);
                	  prpStmt.setLong(2,encounter_nr1);
                	  prpStmt.executeUpdate();
                  }                   
            }
            /*{
            	String sql5="select * from calendar;";
            	Statement stmt5=con2.createStatement();
            	ResultSet rs5 = stmt5.executeQuery(sql5);
            	while(rs5.next())
            	{
            		int id5=rs5.getInt(1);
            		System.out.println(id5);
            		String date5 = rs5.getString(2);
            		System.out.println(date5);
            		String sql6 = "update care_billing_payment set
id='"+id5+"' where payment_date='"+date5+"'";
            		//String sql6 = "update care_billing_payment
set id='0' where payment_date='2007-11-20'";
            		Statement stmt6=con2.createStatement();
            		int i = stmt6.executeUpdate(sql6);
            		System.out.println(i);
            	}
    		}*/
            con2.close();
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}

	}

see this my task

}
 
Is This Answer Correct ?    2 Yes 2 No
Laxmanit08
[Kranium Technology]
 
  Re: Exception in thread "main" java.lang.OutOfMemoryError: Java heap space:
Answer
# 2
Hi Lakshman,


*)Dont retrive all records at a time give limit when ever  
      
 getting records from database.

*) when ever inserting data into database use BatchUpdate
not prpStmt.executeUpdate(); then it will insert all records
at a time.
 
Is This Answer Correct ?    1 Yes 0 No
Kalyan
 
 
 

 
 
 
Other JavaScript Code Interview Questions
 
  Question Asked @ Answers
 
validation code / function to allow only Letters in a text box  1
program that will accept any name and will be stored in an array  2
could you please tell me for what javac, javax,swing,awt.*; are using. what is the meaning and differences. and also there are 4 access modifiers in java. public, private, protected, default. what is the meaning of these 4 access modifiers and difference. public is the access modifier void means return data type disp() means function name what mean by static  1
write a function to validate a given date  1
code to display a Countdown Timer (dynamic)  1
Code for Adding Message and Confirmation Boxes Using JavaScript?  1
code to calculate the number of days between two dates  2
How to test whether two strings are equal or not ?  1
validation code / function to allow only NUmbers in a text box GE3
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space: TCS2
Reading which Character Key was pressed  1
how to delay a function call ?  1
How to Add Message and Confirmation Boxes Using JavaScript?  1
determine which key was pressed and its type  1
 
For more JavaScript Code Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com