• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

OutOfMemory Error

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a servlet
package servlet;
import java.io.*;
import DBAccess.*;
import java.util.*;
import java.sql.*;
import javax.sql.*;
import javax.servlet.*;
import javax.naming.*;
import javax.servlet.http.*;
public class insertBusinessUnit extends HttpServlet
{
boolean p = false;
/*char squote ='\'' ;
char dquote ='\'' ;*/

public void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException
{
String BusinessUnit = request.getParameter("businessunit");
String Description = request.getParameter("description");
ProjectDatabase db = new ProjectDatabase();
/*String bunit =db.changeBusinessQuote(BusinessUnit,squote,dquote);
System.out.println(bunit);*/
p = db.createBusinessUnit(BusinessUnit,Description);
java.io.PrintWriter out = response.getWriter();
if (p)
{
response.setContentType( "text/html" );
out.println( "<html><head><title>IT Architecture Documentation System</title></head>" );
out.println( "<body>" );
out.println("Information is added sucessfully");
out.println( "</body></html>");
}
else
{
response.setContentType( "text/html" );
out.println( "<html><head><title>IT Architecture Documentation System</title></head>" );
out.println( "<body>" );
out.println("Information is not added");
out.println( "</body></html>");
}
out.close();
}
}
this servelet calls a method from ProjectDatbase class
/*public String changeBusinessQuote(String BusinessUnit, char squote, char dquote)
{
StringBuffer buf = new StringBuffer (BusinessUnit);
for (int i = 0; i < buf.length(); i++)
{
if (buf.charAt (i) == squote)
{
buf.append (dquote);
}
}
return buf.toString();
}*/

The problem is if i take the comments out from the servlet and this method, i get this error
Root cause of ServletException
java.lang.OutOfMemoryError
<<no stack trace available>>
if it has comments then it works fine, plz help.
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm thinking you are producing an infinite loop...

Your loop exit condition is i< buf.length(), but you are constantly changing (increasing) the value of buf's length within the loop.

If you simply want to change single quotes to double quotes:
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic