servelet and jdbc programming

servelet and jdbc programming

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... pw = response.getWriter(); String connectionURL = "jdbc:mysql://localhost
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
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
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 [email protected]
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
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
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
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
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 - JDBC
servelet connectivity with oracle using procedure
servelet connectivity with oracle using procedure   kindly elaborate how servlet code connect to oracle br using procedure
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
java servlet programming - JDBC
java servlet programming - 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 ADS_TO_REPLACE_1 JDBC API     JDBC programming interface is found in "java.sql" and "javax.sql"
What is JDBC?
What is JDBC?       JDBC is Java application programming interface that allows the Java... written in the Java programming language.ADS_TO_REPLACE_1 JDBC has been
JDBC
JDBC  why we use batch in jdbc
jdbc
jdbc  Hai , Give a steps for jdbc connectivity
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   how to write program to save data and retrieve data from the form in Java
JDBC
JDBC  how to set classpath for eclipse, java, where to copy jdbc connector
JDBC
JDBC  in class.forname which driver name we are writing for the connection from jdbc to sqlserver 2008
jdbc
jdbc  is it possible to use doget & dopost method with jdbc to call in a servlet programe
jdbc
jdbc  please tell me sir.i dont know JDBC connection and how to create table in database
jdbc
jdbc  why do we need to load jdbc drivers before connecting to database
Jdbc
Jdbc  A java program with jdbc connectivity with insert,delete,update options for name,regno,mark1,mark2,total
JDBC
JDBC  can u send me the code of jdbc how to join two tables that are in relation
jdbc - JDBC
Why JDBC   JDBC used for what
JDBC - JDBC
JDBC - limitations of jdbc  What are the limitations of JDBC
network programming
network programming   Tutorial for Network programming and administration
jdbc
jdbc define batch updates  define batch updates?exp   JDBC... links: http://www.roseindia.net/jdbc/Jdbc-batch-update.shtml http://www.roseindia.net/tutorial/java/jdbc/batchupdateresultsetexample.html
JDBC
JDBC save a data in the database  I need a code to save a data... between java and mysql using JDBC and saves the data into the database. import... con = null; String url = "jdbc:mysql://localhost:3306/"; String db
JDBC
JDBC code to save a data in the database  I need a code to save... the connection between java and mysql using JDBC and saves the data into the database...!"); Connection con = null; String url = "jdbc:mysql://localhost:3306/"; String db
jdbc
how can we set transaction level through jdbc api  how can we set transaction level through jdbc api   Use Connection.setTransactionIsolation(int) to set the desired tansaction level, which takes one of the 5 arguments
jdbc
how can we call stored procedure using jdbc  how can we call stored procedure using jdbc   Call a Stored Procedure using...(); For more information, visit the following link: JDBC call Stored Procedure
Programming with JSP
Programming with JSP  Who will post me the answer
jdbc - JDBC
Java JDBC application  Database Application in Java JDBC
JDBC - JDBC
JDBC Select Count Example   Need an example of count in JDBC
JDBC - JDBC
JDBC -statement types in jdbc  statement types in jdbc
jdbc - JDBC
Loading JDBC driver at runtime  How to load JDBC Driver at runtime
jdbc
jdbc  hey sir i just wanna have some ppt on jdbc coz have my exams next week and i have not attended any classes coz of job... I m studyng frm niit
jdbc
jdbc  I can't run my jdbc program because it has error in this line: public static void main(String[] args) the error is:illegal static declaration in inner class would you please let me whats the problem? regards
jdbc
using jdbc connection   import java.sql.*; public class CreateTable... = DriverManager.getConnection("jdbc:odbc:student"); Class.forName
jdbc
jdbc  i had written jdbc connection in method and i need to get connection in another class?   import java.sql.*; class... driver = "com.mysql.jdbc.Driver"; String url = "jdbc:mysql://localhost:3306/test

Ads