Java Servlet Programing Laungage

Java Servlet Projects

Servlet Project 3

adplus-dvertising
Java Servlet :Inserting Data into database using servlet
Previous Home Next

RegisterServlet.java

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
public class RegisterServlet extends HttpServlet
{
	public void doGet(HttpServletRequest request,HttpServletResponse response) 
	throws ServletException,IOException
	{
	 response.setContentType("text/html");
	 PrintWriter out=response.getWriter();
	 String name=request.getParameter("txtName");
	 String password=request.getParameter("password");
	try
	{
	
Class.forName("oracle.jdbc.driver.OracleDriver"); Connection con=DriverManager.getConnection ("jdbc:oracle:thin:@localhost:1521:xe","system","oracle"); PreparedStatement stmt=con.prepareStatement ("insert into LoginDetails values(?,?)"); stmt.setString(1, name); stmt.setString(2, password); int i=stmt.executeUpdate(); out.println("<b>You are successfully Registered</b>"); con.close(); } catch(Exception e) { out.println("<b>Registration failed</b>"); out.println("<b>Error:</b>" +e); } } }
Previous Home Next