Write a java program to accept mobile handset details through html page and servelt will insert the details in handset table.
import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.sql.*; public class ServletHandset extends HttpServlet { public void doPost(HttpServletRequest r1,HttpServletResponse r2) throws IOException,ServletException { r2.setContentType("text/html"); String s1,s2,s4; double s3; s1=r1.getParameter("Mod"); s2=r1.getParameter("co_name"); s4=r1.getParameter("colour"); s3=Double.parseDouble(r1.getParameter("price")); PrintWriter pw=r2.getWriter(); Connection con=null; PreparedStatement pst=null; String str; int n; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("jdbc:odbc:handset"); str="insert into handset values(?,?,?,?)"; pst=con.prepareStatement(str); pst.setString(1,s1); pst.setString(2,s2); pst.setDouble(3,s3); pst.setString(4,s4); pw.println("Record inserted Successfully!!!"); pst.executeUpdate(); con.commit(); pw.close(); } catch (Exception e) { pw.println(e); pw.close(); } } } /* ServletHandset.html */ method="post" action="http://localhost:8080/uttara/ServletHandset"> Model Number : Mobile Price : Mobile Company Name : Mobile Color Name :
Write a java program to accept mobile handset details through html page and servelt will insert the details in handset table.
Reviewed by
on
April 27, 2015
Rating: