Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa XML servelet and jdbc programming
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Shridhu Chandel
servelet and jdbc programming
3 Answer(s)      5 years and 9 months ago
Posted in : XML



Advertisement
View Answers

March 21, 2009 at 4:17 AM


Hi friend,

Some steps to be remember for solving the problem :

1.Create a html page "stud.html".

<html>

<head>
<title>New Page 1</title>
</head>

<body>



<form method="POST" action="/student">
<!--webbot bot="SaveResults" U-File="fpweb:///_private/form_results.txt";
S-Format="TEXT/CSV" S-Label-Fields="TRUE" -->
<p>Student Name:<input type="text" name="student_name" size="20"></p>
<p>Enrollment No: <input type="text" name="enrollment_no" size="20"></p>
<p>Course Code: <input type="text" name="course_code" size="20"></p>
<p>Regional Center Code: <input type="text" name="regional_center_code" size="20"></p>
<p>E-mail Id: <input type="text" name="email_id" size="20"></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="submit" value="Submit" name="submit"></p>
</form>

</body>

</html>


March 21, 2009 at 4:18 AM


Step 2 : create a servlet class "Student.java"

import java.io.*;
import java.lang.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class Student extends HttpServlet{
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
String connectionURL = "jdbc:mysql://localhost/zulfiqar";;
Connection connection;
try{

String student_name = request.getParameter("student_name");
String enrollment_no = request.getParameter("enrollment_no");
String course_code = request.getParameter("course_code");
String regional_center_code = request.getParameter("regional_center_code");
String email_id = request.getParameter("email_id");

Class.forName("org.gjt.mm.mysql.Driver");
connection = DriverManager.getConnection(connectionURL, "root", "admin");
PreparedStatement pst = connection.prepareStatement("insert into emp_info values(?,?,?,?,?)");

pst.setString(1,student_name);
pst.setString(2,enrollment_no);
pst.setString(1,course_code);
pst.setString(2,regional_center_code);
pst.setString(1,email_id);

int i = pst.executeUpdate();
if(i!=0){
pw.println("<br>Record has been inserted");
}
else{
pw.println("failed to insert the data");
}
}
catch (Exception e){
pw.println(e);
}
}
}


March 21, 2009 at 4:20 AM


3.In web.xml action mapping of servlet.

<?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>abc</servlet-name>
<servlet-class>Student</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>abc</servlet-name>
<url-pattern>/student</url-pattern>
</servlet-mapping>
</web-app>

Thanks


Related Tutorials/Questions & Answers:
servelet and jdbc programming - XML
servelet and jdbc programming  Write a program using Servlet and JDBC for developing an online submission of an examination form. You are required...(); String connectionURL = "jdbc:mysql://localhost/zulfiqar"; Connection
problem in creating web application using servelet, jsp, jdbc and xml - JSP-Servlet
problem in creating web application using servelet, jsp, jdbc and xml  Using Servlet, JSP, JDBC and XML create a web application for a courrier... the technologies JSP,Servlet and JDBC etc... Thanks
Advertisements
Servelet methods
Servelet methods  In my project we use the sendRedirect method which is nt working in our project i would like to know whether there is any other method which can be used instead of sendRedirect
applet and servelet
applet and servelet  How will you establish the connection between the servelet and an applet?  Hi, From applet you can use the URL class to call the servlet. URL servletURL = new URL( location ); URLConnection
java programming - JDBC
java programming  Develop a simple OPAC system for library using even-driven and concurrent programming paradigms of Java. Use JDBC to connect to a back-end database.please reply immediately sir
jsp-servelet,error http404
jsp-servelet,error http404  I am using mysql commandclient to connect with eclipse using jsp and servelet. I keep getting the error hhtp 404...("com.mysql.jdbc.Driver"); Connection con=DriverManager.getConnection("jdbc
Programming error - JDBC
Programming error  import javax.servlet.*; import...=DriverManager.getConnection("jdbc:odbc:Odsn"); Statement s=con.createStatement(); int x...("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc
java programming problem - JDBC
java programming problem  Hi, Request you to provide the source code in Java for the following programming problem : upload .csv file data into oracle database. please send the solution to raichallp@yahoo.in
java programming problem - JDBC
java programming problem  Hi, Request you to provide a solution ( analysis & design & unit test plan & code & test criteria ) to the following problem to the following mail id : Problem : upload excel file data into oracle
java servlet programming - JDBC
programming through servlets Thanx   Hi friend, i am sending multiple
servelet connectivity with oracle using procedure
servelet connectivity with oracle using procedure   kindly elaborate how servlet code connect to oracle br using procedure
Programming in JDBC and JSP - JSP-Servlet
Programming in JDBC and JSP  Write a program using JDBC and JSP to display the names and addresses of all those MCA students at your study centre who have completed/submitted their theory assignments of all the courses of IV
jdbc
jdbc  Write a web based student registration application where the students can register online with their enrollment no. You are required to use JSP, Servelet and JDBC
how to create users using IBM Tivoi API in jsp/servelet?
how to create users using IBM Tivoi API in jsp/servelet?  how to create users using IBM Tivoi API in jsp/servelet
Programming
Programming  Given a number n, write a programming to determine its square root if it is possible, in the contraly case print an appropriate massege on the screen
programming
Java Constructor programming for single and double constructor  write a program which have no argument constructor ,single parameter constructor constructor,double parameter constor,and the now when we create a object
JDBC Architecture
JDBC architecture can be classified in 2 broad categories:- 1. JDBC API 2. Types of JDBC Drivers JDBC API     JDBC programming interface... the Drivers found in JDBC environment, load the most appropriate driver
jdbc
jdbc  Hai , Give a steps for jdbc connectivity
JDBC
JDBC  why we use batch in jdbc
jdbc
jdbc  display the records using index in jdbc
JDBC
JDBC  How to add set of queries in a single query in JDBC
JDBC
JDBC  can u send me the code of jdbc how to join two tables that are in relation
Jdbc
Jdbc  A java program with jdbc connectivity with insert,delete,update options for name,regno,mark1,mark2,total
jdbc
jdbc  is it possible to use doget & dopost method with jdbc to call in a servlet programe
JDBC
JDBC  in class.forname which driver name we are writing for the connection from jdbc to sqlserver 2008
JDBC
JDBC  how to set classpath for eclipse, java, where to copy jdbc connector
jdbc
jdbc  why do we need to load jdbc drivers before connecting to database
jdbc
jdbc   how to write program to save data and retrieve data from the form in Java
Advertisements
 

 

 

DMCA.com