solve this problem
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{ <br />
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("<p><table>" + rs.getString(1) + " " + rs.getInt(2) + "</p></table>");
}
rs.close();
statement.close();
}
catch (Exception e){
System.out.println(e);
}
}
}
XML File for this program
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd"> -->
<web-app>
<servlet>
<servlet-name>Hello</servlet-name>
<servlet-class>DataInsertion</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Hello</servlet-name>
<url-pattern>/DataInsertion</url-pattern>
</servlet-mapping>
</web-app>
View Answers
January 21, 2011 at 12:33 PM
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>
Ads
Related Tutorials/Questions & Answers:
solve this problem
solve this problem I typed this program and compiled.The program is compiled but when i eneterd url in tomcat server. Its not giving error but only... in table please tell me the solution for thid
problem
import java.io.*;
import
help me to solve this problem..
help me to
solve this
problem.. Given below is a class definition for Book. Type and compile the class, and answer the following questions:
class Book {
String title; //bookâ??s title
double price; //bookâ??s price
Advertisements
Solve this problem plzzz
Solve this
problem plzzz Prashant.jsp (this is my JSP file)
<HTML>
<HEAD>
<TITLE>Login using jsp
<BODY>... kindly help me and check all those files and
solve my
problem as soon as possible
how to solve an internet connection problem
how to
solve an internet connection problem when i run my application it give me this error:
Exception in thread "AWT-EventQueue-0" java.lang.UnsupportedOperationException: Not yet implemented
the
problem is that i don`t know
can interface solve this problem in java
can interface
solve this
problem in java I have a JDialog which displays the calendar [from 2010-2020], i created this in a different class... this calander class. can interface
solve this
problem. If yes then how. pls
Please Help To Solve My Problem
Please Help To
Solve My Problem PHP
I Have 6 Textbox and 1 ok... With B Team
when A Team Play With B Team Again Then Generate Error.
I Am
Solve This
Problem With If...Else If...Else Statement But When the More Team
how do i solve this problem?
how do i
solve this
problem? Define a class named Circle with the following properties:
List item
An integer data field named radius with protected access modifier, and a String data field named colour with private access
i need help to solve this problem
i need help to
solve this problem Write a stack class ArrayStack.java implements PureStack interface that reads in strings from standard input and prints them in reverse order. and
Show step by step what queue will look like
Solve it
Solve it How to calculate the value which contains oparator and operand both using command line argument
solve this
solve this
Create a student class. The student object should have studentid, studentname, subject and marks as properties. Also generate the getter and setter methods. Create 5 objects of this class and populate values
solve this pbm
solve this pbm its not working the code for databae access using servlets
how to solve
how to
solve log4j:WARN No appenders could be found for logger (org.apache.struts.util.PropertyMessageResources).
log4j:WARN Please initialize the log4j system properly
solve this pbm
solve this pbm 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
how to solve this..
how to
solve this.. Given a list of students and their marks
Name | Science | Math | English | Computer
Ahmad | 28 | 100 | 66 | 34
Samad | 56 | 89 | 55
how to solve this..
how to
solve this.. Given a list of students and their marks
Name | Science | Math | English | Computer
Ahmad | 28 | 100 | 66 | 34
Samad | 56 | 89 | 55
ModuleNotFoundError: No module named 'solve'
ModuleNotFoundError: No module named '
solve' Hi,
My Python program is throwing following error:
ModuleNotFoundError: No module named '
solve'
How to remove the ModuleNotFoundError: No module named '
solve'
problem in onlinetest...
problem in onlinetest... hi,
my code getting the
problem is ,when user leave a question then the server puts error...
pls help me
javascript problem
javascript problem hi guys
My
problem is that I am using radio button for yes or no but i want to do that if I press yes button then enter... enter
please help me this
problem
Small Bug How to solve in my code
Small Bug How to
solve in my code String season="";
pst...") + ",";
it shows bug in findbugs tool.. but it executes successfully
how to
solve the
problem
help me to solve this question
help me to
solve this question Write a program that inputs a series of integers into an array. The numbers are in the range 0 to 100.
Calculate and display :
a) The Largest number
b) The Smallest Number
c)The sum of the numbers
problem on strings
problem on strings in string1 "123456 ABC DEF...",IN string2 "raveen". iwant to add string2 after 123456 in the first string based on index number.i need logic for this
with out using StringBuffer concept.
Thanks in advanace
Problem with loginbean.jsp
Problem with loginbean.jsp http://www.roseindia.net/jsp/loginbean.shtml
-
I am getting an error in loginbean.jsp.There is some error regarding .What is hello in this?
Also in this example how
compilation problem
compilation problem struts 2.0 : i have included all 5 jars in lib folder,but its giving compilation
problem that package open symphony doesnot... havenot set the build path.if this is the
problem then tell me how to set
compilation problem
compilation problem struts 2.0 : i have included all 5 jars in lib folder,but its giving compilation
problem that package open symphony doesnot... havenot set the build path.if this is the
problem then tell me how to set
Problem with cookies
Problem with cookies Hello All,
i need jsp code for RememberMe module of login.
i am facing
problem with cookies. so please if any one could guide me please help and provide mme the exact code.
Please visit