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

Javabeans Program

The document contains JSP and Java classes for handling student and customer data. It includes a JSP page that uses a JavaBean for a student and another JSP page for customer transactions, which inserts customer data into a MySQL database and forwards to success or failure pages based on the transaction result. The Customer class manages customer information and database interactions, while the Students class handles student names.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views5 pages

Javabeans Program

The document contains JSP and Java classes for handling student and customer data. It includes a JSP page that uses a JavaBean for a student and another JSP page for customer transactions, which inserts customer data into a MySQL database and forwards to success or failure pages based on the transaction result. The Customer class manages customer information and database interactions, while the Students class handles student names.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Demo.

jsp

<jsp:useBean id="Bean1" class="Bean.Students">

<jsp:setProperty name = "Bean1" property ="name" value ="Zara"/>

<jsp:getProperty name = "Bean1" property = "name"/>

</jsp:useBean>

Students.java

package Bean;

public class Students {

public Students() {

private String name;

public String getName() {

return name;

public void setName(String name) {

this.name = name;

}
Customer.java

package javaskool;
import java.io.*;
import java.util.*;
import java.sql.*;

public class Customer implements Serializable


{

private String custID;


private String custName;
private int storeCust;

public String getCustID() {


return custID;
}

public void setCustID(String custID) {


this.custID = custID;
}

public String getCustName() {


return custName;
}

public void setCustName(String custName) {


this.custName = custName;
}

public int setStoreCust()


{
try{
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/db1","root","root");
PreparedStatement pstmt=null;
String query=null;
query="insert into Customer values(?,?)";
pstmt=con.prepareStatement(query);
pstmt.setString(1,custID);
pstmt.setString(2,custName);

int i=pstmt.executeUpdate();

this.storeCust=i;
}
catch(Exception e)
{
}
return storeCust;
}
}

StorCust.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>


<%@ page import="java.util.*" %>
<%@ page import="javaskool.Customer" %>
<html>
<head>
<title>JSP and JavaBean</title>

<%-- create an instance of Customer class --%>


<jsp:useBean id="Customer" class="javaskool.Customer">
<jsp:setProperty name = "Customer" property ="custID" value ="C12"/>
<jsp:setProperty name = "Customer" property ="custName" value ="Archana"/>
<jsp:getProperty name = "Customer" property = "custID"/>
<jsp:getProperty name = "Customer" property = "custName"/>

</jsp:useBean>

</head>
<body>

<%
int x=Customer.setStoreCust();

if(x>=1)
{
%>
<jsp:forward page="Success.jsp" />
<%

}
else
{
%>
<jsp:forward page="Failure.jsp" />
<%

}
%>
</body>
</html>

Success.jsp
<%

out.println("<html>");
out.println("<Body>");
out.println("<B><center>Thank you for purchasing with us....</center><b><br><br>");
out.println("</Body>");
out.println("</html>");

%>

Failure.jsp

<%

out.println("<html>");
out.println("<Body>");
out.println("<B><center>Sorry, Your Transaction is failed....</center><b><br><br>");
out.println("</Body>");
out.println("</html>");

%>

You might also like