0% found this document useful (0 votes)
4 views2 pages

Practical No 7 - C

demo project
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Practical No 7 - C

demo project
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

7c.

Develop simple Marks Entry Application to demonstrate accessing Database using


EJB.
index.html

<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="RBServlet" >
Enter Student Name<input type="text" name="sname" ><br>
Enter Subject 1<input type="text" name="sub1"><br>
Enter Subject 2<input type="text" name="sub2" ><br>
<input type="reset" value="RE-ENTER"><input type="submit" value="SUBMIT">
</form>
</body>
-------------------------
RRBean.java
package mybeans;
import javax.ejb.Stateless;
import java.sql.*;
@Stateless
public class RRBean {
public RRBean(){}
public String markenter(String n, String s1,String s2){
String msg;
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/marksdb","root","root");
String query="insert into studentdata values(?,?,?)";
PreparedStatement pst = con.prepareStatement(query);
pst.setString(1,n);
pst.setString(2,s1);
pst.setString(3,s2);
pst.executeUpdate();

msg="Marks entered";
}
catch(Exception e){msg=""+e;}
return msg;
}
}

------------------------
RBServlet.java
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ejb.EJB;
import mybeans.RRBean;

public class RBServlet extends HttpServlet {


@EJB RRBean obj;
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String s1=request.getParameter("sub1");
String n=request.getParameter("sname");
String s2=request.getParameter("sub2");
String msg = obj.markenter(n, s1, s2);
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
out.println(msg);
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet RBServlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet RBServlet at " + request.getContextPath() +
"</h1>");
out.println("</body>");
out.println("</html>");
}
}
}

----------------------------------
create table studentdata(sname varchar(10) , sub1 varchar(10), sub2 varchar(10));
insert into emp values('1','aaa','221234','11');

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy