
sir rows are also inserting i have checked in the database also the rows are not affected in the table .
The first pbm wich i have sent to you is not yet solved.......... pls give me detail explaination how we can execute the program

Hi Friend,
Follow these steps to create and execute a servlet:
Put servlet-api.jar inside the lib folder of apache tomcat. 1)create a servlet.
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class DataInsertion extends HttpServlet{
public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String url = "jdbc:mysql://localhost/test?user=root&password=root";
Connection conn;
ResultSet rs;
try{
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(url);
Statement statement = conn.createStatement();
String query = "insert into emp(EMP_NAME,SALARY) values('roseindia', 10000)";
int i = statement.executeUpdate(query);
if(i!=0){
out.println("The record has been inserted<br>");
}
else{
out.println("Sorry! Failure");
}
rs = statement.executeQuery("select * from emp");
while(rs.next()){
out.println(""+rs.getString("EMP_NAME") + " " + rs.getInt("SALARY") + "<br>");
}
rs.close();
statement.close();
}
catch (Exception e){
System.out.println(e);
}
}
}
2)Go to the webapps folder of your apache tomcat and create a web application folder but it should having an appropriate name like examples.
3)Create web.xml and classes folder inside the WEB_INF folder of web application folder assuming 'examples'.
4)Copy the servlet to the classes folder.
5)Edit the web.xml to include servlet?s name and url pattern.
<servlet>
<servlet-name>DataInsertion</servlet-name>
<servlet-class>DataInsertion</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DataInsertion</servlet-name>
<url-pattern>/DataInsertion</url-pattern>
</servlet-mapping>
6)Compile your servlet.
7)Run Tomcat server by clicking the startup.bat file. This is located inside the bin folder of apache tomcat.
8)Open the browser and type the following url:
http://localhost:8080/examples/HellWorld
Thanks
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.