Escolar Documentos
Profissional Documentos
Cultura Documentos
Click Start > Control Panel > Administrative Tools > Data Sources (ODBC).
The ODBC Data Source Administrator window appears.
Click “Driver do Micorsoft Access (*.mdb) option . click Finish.
Select Microsoft Access Driver (*.mdb) and click Finish. The ODBC Microsoft
Access Setup window appears.
Enter the Data Source Name. In this example we created a data source called sss.
Client and server program using Netbeans
Step 1:
If you wish , u can choose a dedicated Project location using browse option .
Step 6:
Type the following code inside the <body> tag and save the file.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form action="">
<input type="text" name="amount">
<input type="submit" value="submit the amount">
</form>
</body>
</html>
Step 7:
Servlet opens.
Copy the url of the servlet and paste it in the index.jsp file.
Get the text box (amount) value of web page through the following code
int a=Integer.parseInt(request.getParameter("amount"));
Step 17:
Add the business method “deposit”
Give the return types as “int”
Add the parameter ‘amount ‘ and its return data type as “int”
Click “ok”
Step 18:
@Stateful
public class Stateful_session_guna_example implements
Stateful_session_guna_exampleRemote {
int bal=5000;
@Override
public int deposit(int amount) {
bal=bal+amount;
return bal;
}
************4444444
Step 19:
Once again goto the same set of options to create a new session bean.
Step 20
Step 23:
Add the business method “update_query”
Give the return types as “String”
import javax.ejb.Stateful;
import java.sql.*;
/**
*
* @author gunaseeli
*/
@Stateful
public class NewSessionBean_q_viji implements NewSessionBean_q_vijiRemote {
@Override
public String update(int bal) {
try{
Statement st;
Connection con=null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:vvv");
st=con.createStatement();
String sql="insert into list values('"+bal+"')";
st.executeUpdate(sql);
st.close();
}
catch (Exception e)
{
}
return "it's saved";
888888888888888888888888888888888888888888888
Step 24:
STEP 26:
Choose the beans from the list.
Step 27:
Stateful_session_guna_exampleRemote stateful_session_guna_example
= lookupStateful_session_guna_exampleRemote();
Two Remote interface will be created. One for balance updation and another for
Updation the balance amount in the database.
Step 28:
Call the business method “deposit” and “update” through the remote interfaces
int x= Integer.parseInt(request.getParameter("amt"));
int y=newSessionBean_viji.deposit(x);
String s=newSessionBean_q_viji.update(y);print the value of s
****
Print s
step 29:
Go to the project window. Right click on the project
Stateful_new_example - Run
Step 30:
Web page opens. Enter the an amount and click the submit button.
Step 26:
OUTPUT window
Now go to the table list in ms access database and check out the whether the
updated balance is inserted or not.
Once again go the client page and give some other amount.For eg Rs.2000
Once again go to the table list in ms access database and check out the whether the
newly updated balance is inserted or not.
**********************************************************************
import ejbb.Stateful_session_guna_exampleRemote;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
* @author gunaseeli
*/
@WebServlet(name="Stateful_example_guna_servlet",
urlPatterns={"/Stateful_example_guna_servlet"})
public class Stateful_example_guna_servlet extends HttpServlet {
Stateful_session_guna_exampleRemote stateful_session_guna_example =
lookupStateful_session_guna_exampleRemote();
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
methods.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
int a=Integer.parseInt(request.getParameter("amount"));
try {
int y = stateful_session_guna_example.deposit(a);
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet Stateful_example_guna_servlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>The balance is " + y + "</h1>");
out.println("</body>");
out.println("</html>");
} finally {
out.close();
}
}
/**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Returns a short description of the servlet.
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
private Stateful_session_guna_exampleRemote
lookupStateful_session_guna_exampleRemote() {
try {
Context c = new InitialContext();
return (Stateful_session_guna_exampleRemote)
c.lookup("java:global/Stateful_new_example/Stateful_new_example-
ejb/Stateful_session_guna_example!ejbb.Stateful_session_guna_exampleRemote");
} catch (NamingException ne) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught",
ne);
throw new RuntimeException(ne);
}
}
***********************************************************
Index.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form action="Stateful_example_guna_servlet">
<input type="text" name="amount">
<input type="submit" value="submit the amount">
</form>
</body>
</html>
******************************************************************
Bean
package ejbb;
import javax.ejb.Stateful;
/**
*
* @author gunaseeli
*/
@Stateful
public class Stateful_session_guna_example implements
Stateful_session_guna_exampleRemote {
int bal=5000;
@Override
public int deposit(int amount) {
bal=bal+amount;
return bal;
}
}
******************************************************************
Update query program
package ejbb;
import javax.ejb.Stateful;
import java.sql.*;
/**
*
* @author gunaseeli
*/
@Stateful
public class NewSessionBean_q_viji implements NewSessionBean_q_vijiRemote {
@Override
public String update(int bal) {
try{
Statement st;
Connection con=null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:vvv");
st=con.createStatement();
String sql="insert into list values('"+bal+"')";
st.executeUpdate(sql);
st.close();
catch (Exception e)
{
}
return "it's saved";