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");
       [B] String vsql = "insert into employee values("+vno+",'"+vname+"')";[/B]
        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.

<HTML>
<BODY>
           <form method="get" action="sdbapp">
               Enter No : 
               <input type="text" name="no"><br>
               Enter Name:
               <input type="text" name="name"><br>
               <input type="submit" value="send">
           </form>
</BODY>
</HTML>

And this is the web.xml

<web-app>
     <servlet>
         <servlet-name>sdbapp</servlet-name>
         <servlet-class>SDBApp</servlet-class>
     </servlet>
     <servlet-mapping>
     <servlet-name>sdbapp</servlet-name>
     <url-pattern>/sdbapp</url-pattern>
     </servlet-mapping>
</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.

Recommended Answers

All 5 Replies

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

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.

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.

Yes Ezzaral your correct. Now it is working.
Thanks to you Mr. Ezzaral

it solve my problem
thanku u very much........

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.