java.lang.NoClassDefFoundError: java/lang/StringBuilder

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: May 2007
Posts: 4
Reputation: sasidhar1229 is an unknown quantity at this point 
Solved Threads: 0
sasidhar1229 sasidhar1229 is offline Offline
Newbie Poster

java.lang.NoClassDefFoundError: java/lang/StringBuilder

 
0
  #1
Sep 3rd, 2007
I am doing servlet program. It is working when I run it as a GUI appliction.

But when I run it as a web application it arises java.lang.NoClassDefFoundError: java/lang/StringBuilder
at SDBApp.service(SDBApp.java:14)please help me.
Here is my code.
SDBApp.java
/*servlet which takes care of inserting rows in Data Base*/
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class SDBApp extends HttpServlet
{
    private Connection con;
    private Statement stmt;
    public void service(HttpServletRequest sreq,HttpServletResponse sresp){
        DBConnection dbcon = new DBConnection(con);
        con = dbcon.dbConnection();
        String vno =sreq.getParameter("no");
        String vname = sreq.getParameter("name");
        String vsql = "insert into employee values("+vno+",'"+vname+"')";
        try{
        stmt = con.createStatement();
        stmt.executeUpdate(vsql);
        }catch(Exception e){}
    }
};
I marked red letters where I am getting problems.
But It is working in GUI application.

This is url : http://localhost:7001/dbapp/formone.html

Here is the html form formone.html which we sends request to.

  1. <HTML>
  2. <BODY>
  3. <form method="get" action="sdbapp">
  4. Enter No :
  5. <input type="text" name="no"><br>
  6. Enter Name:
  7. <input type="text" name="name"><br>
  8. <input type="submit" value="send">
  9. </form>
  10. </BODY>
  11. </HTML>
And this is the web.xml
  1. <web-app>
  2. <servlet>
  3. <servlet-name>sdbapp</servlet-name>
  4. <servlet-class>SDBApp</servlet-class>
  5. </servlet>
  6. <servlet-mapping>
  7. <servlet-name>sdbapp</servlet-name>
  8. <url-pattern>/sdbapp</url-pattern>
  9. </servlet-mapping>
  10. </web-app>
Here is the problem where it arises
String vsql = "insert into employee values("+vno+",'"+vname+"')";

In the DataBase
we have employee table.with two columns no which is number and name which is varchar2(14)

If we use selet * from employee in above program It is working in web application.
please help me.
Attached Files
File Type: java SDBApp.java (642 Bytes, 1 views)
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,272
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 493
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: java.lang.NoClassDefFoundError: java/lang/StringBuilder

 
0
  #2
Sep 3rd, 2007
You forgot to put single quotes before and after double quotes on first inserted value vno
String vsql = "insert into employee values('"+vno+"','"+vname+"')";

That should sort your problem
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4
Reputation: sasidhar1229 is an unknown quantity at this point 
Solved Threads: 0
sasidhar1229 sasidhar1229 is offline Offline
Newbie Poster

Re: java.lang.NoClassDefFoundError: java/lang/StringBuilder

 
0
  #3
Sep 4th, 2007
Originally Posted by peter_budo View Post
You forgot to put single quotes before and after double quotes on first inserted value vno
String vsql = "insert into employee values('"+vno+"','"+vname+"')";

That should sort your problem
Thanks peter_budo.I tried your suggestion but it is not working.

The same problem I am getting.

Above I mentioned that I ran the same program Using GUI application there it is running.

And also the "vno" field is "number" in Data Base.

Here is the table in DB

employee(no number(3),name varchar2(15));

PLEASE HELP ME TO SOLVE THIS PROBLEM.

Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,514
Reputation: Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future 
Solved Threads: 523
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: java.lang.NoClassDefFoundError: java/lang/StringBuilder

 
0
  #4
Sep 4th, 2007
You are probably getting the java.lang.NoClassDefFoundError: java/lang/StringBuilder error because you compiled the servlet under 1.5 or above and your app server is running 1.4. StringBuilder was introduced in java 1.5.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4
Reputation: sasidhar1229 is an unknown quantity at this point 
Solved Threads: 0
sasidhar1229 sasidhar1229 is offline Offline
Newbie Poster

Re: java.lang.NoClassDefFoundError: java/lang/StringBuilder

 
0
  #5
Sep 4th, 2007
Yes Ezzaral your correct. Now it is working.
Thanks to you Mr. Ezzaral
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 7274 | Replies: 4
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC