
I typed this program and compiled.The program is compiled but when i eneterd url in tomcat server. Its not giving error but only blank page is coming the text is not displaying and row is also inserted in table please tell me the solution for thid problem
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/zulfiqar?user=root&password=admin";
Connection conn;
ResultSet rs;
try{
Class.forName("org.gjt.mm.mysql.Driver");
conn = DriverManager.getConnection(url);
Statement statement = conn.createStatement();
String query = "insert into emp_sal values('zulfiqar', 15000)";
int i = statement.executeUpdate(query);
if(i!=0){
out.println("The record has been inserted");
}
else{
out.println("Sorry! Failure");
}
rs = statement.executeQuery("select * from emp_sal");
while(rs.next()){
out.println("
XML File for this program

Hello Friend,
Here is our code. Check it.
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);
}
}
}
In web.xml:
<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>
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.