BMPBEANBean.java
资源名称:某公司的java培训教材 [点击查看]
上传用户:dinglihq
上传日期:2013-02-04
资源大小:99958k
文件大小:4k
源码类别:
Java编程
开发平台:
Java
- package com.cwj.userjmssesenbdb;
- import javax.ejb.*;
- import java.sql.*;
- import javax.naming.*;
- public class BMPBEANBean implements EntityBean {
- EntityContext entityContext;
- java.lang.String shancbz;
- java.lang.String xiwbz;
- Context ctx;
- public BMPBEANPK ejbCreate(java.lang.String shancbz, java.lang.String xiwbz) throws CreateException {
- /**@todo Complete this method*/
- PreparedStatement pstmt = null;
- Connection conn = null;
- setShancbz(shancbz);
- setXiwbz(xiwbz);
- try {
- System.out.println("ejbCreate() called.");
- this.shancbz = shancbz;
- this.xiwbz = xiwbz;
- conn = getConnection();
- pstmt = conn.prepareStatement(
- "insert into aa11 (shancbz, xiwbz) values (?, ?)");
- pstmt.setString(1, shancbz);
- pstmt.setString(2, xiwbz);
- pstmt.executeUpdate();
- return new BMPBEANPK(shancbz);
- }catch (Exception e) {
- throw new CreateException(e.toString());
- }
- finally {
- try {
- if (pstmt != null) {
- pstmt.close();
- }
- }
- catch (Exception e) {}
- try {
- if (conn != null) {
- conn.close();
- }
- }
- catch (Exception e) {}
- }
- }
- public void ejbPostCreate(java.lang.String shancbz, java.lang.String xiwbz) throws CreateException {
- /**@todo Complete this method*/
- }
- public void ejbRemove() throws RemoveException {
- /**@todo Complete this method*/
- }
- public void ejbLoad() {
- /**@todo Complete this method*/
- }
- public void ejbStore() {
- /**@todo Complete this method*/
- }
- public void ejbActivate() {
- /**@todo Complete this method*/
- }
- public void ejbPassivate() {
- /**@todo Complete this method*/
- }
- public void unsetEntityContext() {
- this.entityContext = null;
- }
- public void setEntityContext(EntityContext entityContext) {
- this.entityContext = entityContext;
- }
- public void setShancbz(java.lang.String shancbz) {
- this.shancbz = shancbz;
- }
- public void setXiwbz(java.lang.String xiwbz) {
- this.xiwbz = xiwbz;
- }
- public java.lang.String getShancbz() {
- return shancbz;
- }
- public java.lang.String getXiwbz() {
- return xiwbz;
- }
- public java.lang.String ejbFindByPrimaryKey(java.lang.String untitledField1) throws FinderException {
- /**@todo Complete this method*/
- return null;
- }
- public BMPBEANPK ejbFindByPrimaryKey(BMPBEANPK pk) throws FinderException {
- /**@todo Complete this method*/
- return null;
- }
- public java.sql.Connection getConnection() throws Exception {
- try {
- ctx = new InitialContext();
- javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup(
- "TestDataSource");
- return ds.getConnection();
- }
- catch (Exception ex) {
- System.err.println("Could not locate datasource! Reason:");
- ex.printStackTrace();
- throw ex;
- }
- }
- public BMPBEANPK ejbHomeEjbInsertAa11(String shancbz, String xiwbz) throws CreateException {
- PreparedStatement pstmt=null;
- Connection conn=null;
- try{
- System.out.println("ejbHomeEjbInsertAa11() called");
- this.shancbz=shancbz;
- this.xiwbz=xiwbz;
- conn=getConnection();
- pstmt=conn.prepareStatement("insert into aa11(shancbz,xiwbz)values(?,?)");
- pstmt.setString(1,shancbz);
- pstmt.setString(2,xiwbz);
- pstmt.executeUpdate();
- return new BMPBEANPK(shancbz);
- }
- catch(Exception e){
- throw new CreateException(e.toString());
- }
- finally {
- try {
- if (pstmt != null) {
- pstmt.close();
- }
- }
- catch (Exception e) {}
- try {
- if (conn != null) {
- conn.close();
- }
- }
- catch (Exception e) {}
- }
- }
- public BMPBEANPK ejbHomeEjbdeleteAa11(String shancbz) {
- /**@todo Complete this method*/
- return null;
- }
- }