当前位置: 技术问答>java相关
各位高手能提供一个简单的bmp模式的ejb的例子么,数据库oracle
来源: 互联网 发布时间:2017-04-18
本文导语: ru ti | package ren.welcome.EntityBean.sportBean.bmp; import javax.ejb.*; import javax.naming.*; import java.rmi.RemoteException; import java.sql.Connection; import java.sql.SQLException; import java.sql.PreparedStatement; import java.sql.R...
ru ti
|
package ren.welcome.EntityBean.sportBean.bmp;
import javax.ejb.*;
import javax.naming.*;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.sql.DataSource;
import java.util.*;
import ren.welcome.EntityBean.sportBean.BaseClass;
public class SportTeamEJB extends BaseClass implements EntityBean
{
public String sport;
public String nickName;
public String ownerName;
public String franchisePlayer;
EntityContext ctx;
public SportTeamPK ejbCreate(String sport, String nickName) throws CreateException {
this.sport = sport;
this.nickName = nickName;
ownerName = null;
franchisePlayer = null;
Connection con = null;
try
{
con = getConnection(); // this method is detailed later
PreparedStatement statement =
con.prepareStatement ("INSERT INTO SPORTSTEAMS (SPORT, NICKNAME) " +
"VALUES (?, ?)");
statement.setString(1, sport);
statement.setString(2, nickName);
if (statement.executeUpdate() != 1)
{
throw new CreateException("Failed to create sports team.");
}
}
catch (SQLException sqle)
{
throw new EJBException(sqle);
}
finally
{
try
{
if (con != null)
{
con.close();
}
}
catch (SQLException sqle)
{}
}
return new SportTeamPK(sport, nickName);
}
public void ejbPostCreate(String key, String relatedData) {}
public SportTeamPK ejbCreate(String sport, String nickName, String ownerName, String franchisePlayer) throws javax.ejb.CreateException {
this.sport = sport;
this.nickName = nickName;
this.ownerName = ownerName;
this.franchisePlayer = franchisePlayer;
Connection con = null;
try {
con = getConnection();
PreparedStatement statement =
con.prepareStatement("INSERT INTO SPORTSTEAMS (SPORT, NICKNAME, " +
"OWNERNAME, FRANCHISEPLAYER ) VALUES " +
"(?, ?, ?, ?)");
statement.setString(1, sport);
statement.setString(2, nickName);
statement.setString(3, ownerName);
statement.setString(4, franchisePlayer);
if (statement.executeUpdate() != 1) {
throw new CreateException("Failed to create sports team.");
}
} catch (SQLException sqle) {
throw new EJBException(sqle);
}
finally {
try {
if (con != null) {
con.close();
}
} catch (SQLException sqle) {}
}
return new SportTeamPK(sport, nickName);
}
public void ejbPostCreate(String sport, String nickName, String ownerName, String franchisePlayer) {}
public void setEntityContext(EntityContext ctx)
{
this.ctx = ctx;
}
import javax.ejb.*;
import javax.naming.*;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.sql.DataSource;
import java.util.*;
import ren.welcome.EntityBean.sportBean.BaseClass;
public class SportTeamEJB extends BaseClass implements EntityBean
{
public String sport;
public String nickName;
public String ownerName;
public String franchisePlayer;
EntityContext ctx;
public SportTeamPK ejbCreate(String sport, String nickName) throws CreateException {
this.sport = sport;
this.nickName = nickName;
ownerName = null;
franchisePlayer = null;
Connection con = null;
try
{
con = getConnection(); // this method is detailed later
PreparedStatement statement =
con.prepareStatement ("INSERT INTO SPORTSTEAMS (SPORT, NICKNAME) " +
"VALUES (?, ?)");
statement.setString(1, sport);
statement.setString(2, nickName);
if (statement.executeUpdate() != 1)
{
throw new CreateException("Failed to create sports team.");
}
}
catch (SQLException sqle)
{
throw new EJBException(sqle);
}
finally
{
try
{
if (con != null)
{
con.close();
}
}
catch (SQLException sqle)
{}
}
return new SportTeamPK(sport, nickName);
}
public void ejbPostCreate(String key, String relatedData) {}
public SportTeamPK ejbCreate(String sport, String nickName, String ownerName, String franchisePlayer) throws javax.ejb.CreateException {
this.sport = sport;
this.nickName = nickName;
this.ownerName = ownerName;
this.franchisePlayer = franchisePlayer;
Connection con = null;
try {
con = getConnection();
PreparedStatement statement =
con.prepareStatement("INSERT INTO SPORTSTEAMS (SPORT, NICKNAME, " +
"OWNERNAME, FRANCHISEPLAYER ) VALUES " +
"(?, ?, ?, ?)");
statement.setString(1, sport);
statement.setString(2, nickName);
statement.setString(3, ownerName);
statement.setString(4, franchisePlayer);
if (statement.executeUpdate() != 1) {
throw new CreateException("Failed to create sports team.");
}
} catch (SQLException sqle) {
throw new EJBException(sqle);
}
finally {
try {
if (con != null) {
con.close();
}
} catch (SQLException sqle) {}
}
return new SportTeamPK(sport, nickName);
}
public void ejbPostCreate(String sport, String nickName, String ownerName, String franchisePlayer) {}
public void setEntityContext(EntityContext ctx)
{
this.ctx = ctx;
}