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.