Write a java program to accept student roll number from html page & servlet will the details of student like name, address etc. Assume student table is already present.
import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.sql.*; public class StudentDetails extends HttpServlet { public void doGet(HttpServletRequest r1,HttpServletResponse r2) throws IOException,ServletException { r2.setContentType("text/html"); PrintWriter pw=r2.getWriter(); pw.println(" pw.println(" pw.println(" "); pw.println("Roll Number:"); pw.println(""); pw.println(" "); pw.println("Name:"); pw.println(""); pw.println(" "); pw.println("Class"); pw.println(""); pw.println(" "); pw.println("Address:"); pw.println(""); pw.println(" "); pw.println(""); pw.println(" "); pw.println(" "); pw.println(" "); } public void doPost(HttpServletRequest r1,HttpServletResponse r2) throws IOException,ServletException { r2.setContentType("text/html"); Connection con=null; Statement st=null; // Resultset rs=null; String str=""; int n=0; String s1,s2,s3,s4; s1=r1.getParameter("rno"); s2=r1.getParameter("sname"); s3=r1.getParameter("class"); s4=r1.getParameter("add"); PrintWriter pw=r2.getWriter(); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); } catch(Exception e) { System.out.println(e); } try { con=DriverManager.getConnection("jdbc:odbc:stu_det_slip23"); } catch(Exception e) { System.out.println(e); } try { st=con.createStatement(); } catch(Exception e) { System.out.println(e); } str="insert into studentdetails values('"+s1+"','"+s2+"','"+s3+"','"+s4+"')"; try { n = st.executeUpdate(str); } catch(Exception e) { System.out.println(e); } if(n>0) pw.println("Record inserted successfully!!!"); else pw.println("Record not inserted!!!"); } }
Write a java program to accept student roll number from html page & servlet will the details of student like name, address etc. Assume student table is already present.
Reviewed by
on
April 27, 2015
Rating: