⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bmp3.html

📁 jdbc书
💻 HTML
📖 第 1 页 / 共 2 页
字号:
    RegistrationPK primaryKey = new RegistrationPK();
    primaryKey.theuser = theuser;
    return primaryKey;
    } catch (CreateException ce) {
      throw ce;
    } catch (SQLException sqe) {
      throw new CreateException (sqe.getMessage());
    } finally {
      try {
         ps.close();
      } catch (Exception ignore) {}
      try {
         con.close();
      } catch (Exception ignore) {}
    }
}
</PRE>

<FONT FACE="Verdana, Arial, Helvetica, sans-serif">

<A NAME="load"></A>
<H3>Load Method</H3>

This method gets the primary key from the entity context
and passes it to the <CODE>refresh</CODE> method which loads the
data.

</FONT>

<PRE>
  public void ejbLoad() throws RemoteException {
    try {
      refresh((RegistrationPK) ctx.getPrimaryKey());
    }
    catch (FinderException fe) {
      throw new RemoteException (fe.getMessage());
    }
  }
</PRE>

<FONT FACE="Verdana, Arial, Helvetica, sans-serif">

<A NAME="refresh"></A>
<H3>Refresh Method</H3>

<P>
The <CODE>refresh</CODE> method is programmer-supplied code
to load the data from the database. It checks the primary key 
value, gets a connection to the database, and creates a
<CODE>PreparedStatement</CODE> object for querying
the database for the user specified in the primary key.

<P>
Data is read from the database into a <CODE>ResultSet</CODE>
and assigned to the global member variables so the 
<CODE>RegistrationBean</CODE> has the most up-to-date information
for the user.

</FONT>

<PRE>
private void refresh(RegistrationPK pk)
             throws FinderException, RemoteException {

  if (pk == null) {
    throw new RemoteException ("primary key 
				cannot be null");
  }
  Connection con = null;
  PreparedStatement ps = null;
  try {
     con=getConnection();
     ps=con.prepareStatement("select password, 
		emailaddress, creditcard, 
		balance from registration 
		where theuser = ?");
     ps.setString(1, pk.theuser);
     ps.executeQuery();
     ResultSet rs = ps.getResultSet();
     if (rs.next()) {
       theuser = pk.theuser;
       password = rs.getString(1);
       emailaddress = rs.getString(2);
       creditcard = rs.getString(3);
       balance = rs.getDouble(4);
     }
     else {
        throw new FinderException (
                    "Refresh: Registration ("
                    + pk.theuser + ") not found");
     }
  }
  catch (SQLException sqe) {
     throw new RemoteException (sqe.getMessage());
  }
  finally {
     try {
        ps.close();
     }
     catch (Exception ignore) {}
     try {
        con.close();
     }
     catch (Exception ignore) {}
  }
}
</PRE>

<FONT FACE="Verdana, Arial, Helvetica, sans-serif">

<A NAME="store"></A>
<H3>Store Method</H3>

This method gets a database connection and creates a 
<CODE>PreparedStatement</CODE> to update the database. 

</FONT>

<PRE>
public void ejbStore() throws RemoteException {
  Connection con = null;
  PreparedStatement ps = null;
  try {
     con = getConnection();
     ps = con.prepareStatement("update registration 
				set password = ?, 
				emailaddress = ?, 
				creditcard = ?, 
				balance = ? 
				where theuser = ?");
     ps.setString(1, password);
     ps.setString(2, emailaddress);
     ps.setString(3, creditcard);
     ps.setDouble(4, balance);
     ps.setString(5, theuser);
     int i = ps.executeUpdate();
     if (i == 0) {
       throw new RemoteException (
                   "ejbStore: Registration (
		   " + theuser + ") not updated");
     }
  } catch (RemoteException re) {
       throw re;
  } catch (SQLException sqe) {
       throw new RemoteException (sqe.getMessage());
  } finally {
    try {
       ps.close();
    } catch (Exception ignore) {}
     try {
        con.close();
     }
     catch (Exception ignore) {}
  }
}
</PRE>

<FONT FACE="Verdana, Arial, Helvetica, sans-serif">


<A NAME="find"></A>
<H3>Find Method</H3>

The <CODE>ejbFindByPrimaryKey</CODE> method matches the signature
of the <CODE>FindByPrimaryKey</CODE> method in the
<A HREF="./Code/registration/RegistrationHome.java">RegistrationHome</A>
interface. It calls the <CODE>refresh</CODE> method to get or
refresh the user data for the user specified by the primary key.

<P>
The container-managed persistence version of <CODE>RegistrationBean</CODE> 
does not implement this method because the container handles getting
and refreshing the user data.

</FONT>

<PRE>
public RegistrationPK ejbFindByPrimaryKey(
		RegistrationPK pk)
           	throws FinderException, 
           	RemoteException {

  if ((pk == null) || (pk.theuser == null)) {
     throw new FinderException ("primary key 
				 cannot be null");
  }
  refresh(pk);
  return pk;
}
</PRE>

<FONT FACE="Verdana, Arial, Helvetica, sans-serif">

<P ALIGN="RIGHT">
<FONT SIZE="-1">[<A HREF="#top">TOP</A>]</FONT>

</FONT>
</TD>
</TR>
</TABLE>




<!-- ================ -->
<!-- End Main Content -->
<!-- ================ -->

</TD>
</TR>
</TABLE>

<!-- Copyright Insert -->

<BR CLEAR="ALL">

<FORM ACTION="/cgi-bin/search.cgi" METHOD="POST">
<TABLE WIDTH="100%" CELLPADDING="0" BORDER="0" CELLSPACING="5">   
  <TR>
    <TD VALIGN="TOP">
	
    <P ALIGN=CENTER>
    <FONT SIZE="-1" COLOR="#999999" FACE="Verdana, Arial, Helvetica, sans-serif">
    [ This page was updated: <!-- new date --> 13-Oct-99 ]</font></P>
    </TD>
  </TR>
  
  <TR>
    <TD BGCOLOR="#CCCCCC">
    <IMG SRC="/images/pixel.gif" HEIGHT="1" WIDTH="1" ALT=""></TD>
  </TR>
  
  <TR>
    <TD>
    <CENTER>
    <FONT SIZE="-2" FACE="Verdana, Arial, Helvetica, sans-serif">
    <A HREF="http://java.sun.com/products/">Products &amp; APIs</A> | 
    <A HREF="/developer/index.html">Developer Connection</A> | 
    <A HREF="/developer/infodocs/index.shtml">Docs &amp; Training</A> | 
    <A HREF="/developer/support/index.html">Online Support</A><BR>
    <A HREF="/developer/community/index.html">Community Discussion</A> |
    <A HREF="http://java.sun.com/industry/">Industry News</A> | 
    <A HREF="http://java.sun.com/solutions">Solutions Marketplace</A> | 
    <A HREF="http://java.sun.com/casestudies">Case Studies</A>
    </FONT>
    </CENTER>
    </TD>
  </TR>
  
  <TR>
    <TD BGCOLOR="#CCCCCC">
    <IMG SRC="/images/pixel.gif" HEIGHT="1" WIDTH="1" ALT=""></TD>
  </TR>

  <TR>
    <TD ALIGN="CENTER">
    <FONT SIZE="-2" FACE="Verdana, Arial, Helvetica, sans-serif">
    <A HREF="http://java.sun.com/docs/glossary.html">Glossary</A> - 
    <A HREF="http://java.sun.com/applets/">Applets</A> - 
    <A HREF="http://java.sun.com/docs/books/tutorial/">Tutorial</A> - 
    <A HREF="http://java.sun.com/jobs/">Employment</A> - 
    <A HREF="http://java.sun.com/nav/business/">Business &amp; Licensing</A> - 
    <A HREF="http://java.sun.com/javastore/">Java Store</A> -
    <A HREF="http://java.sun.com/casestudies/">Java in the Real World</A>
    </FONT>
    </TD>
  </TR>

  <TR>
    <TD>
    <CENTER>
    <FONT SIZE="-2" FACE="Verdana, Arial, Helvetica, sans-serif">
    <a href="/siteinfo/faq.html">FAQ</a> |
    <a href="/feedback/index.html">Feedback</a> | 
    <a href="http://www.dynamicdiagrams.net/mapa/cgi-bin/help.tcl?db=javasoft&dest=http://java.sun.com/">Map</a> | 
    <A HREF="http://java.sun.com/a-z/index.html">A-Z Index</A>
    </FONT>
    </CENTER>

    </TD>
  </TR>
  
  <TR>
    <TD>

    <TABLE WIDTH="100%" CELLPADDING="0" BORDER="0" CELLSPACING="0">
      <TR>
        <TD WIDTH="50%">
        <FONT SIZE="-2" FACE="Verdana, Arial, Helvetica, sans-serif">
        For more information on Java technology<BR>
        and other software from Sun Microsystems, call:<BR>
        </FONT>
        <FONT SIZE="-1" FACE="Verdana, Arial, Helvetica, sans-serif">
        (800) 786-7638<BR></FONT>
        <FONT SIZE="-2" FACE="Verdana, Arial, Helvetica, sans-serif">
        Outside the U.S. and Canada, dial your country's 
        <A HREF="http://www.att.com/business_traveler/attdirecttollfree/">AT&amp;T&nbsp;Direct&nbsp;Access&nbsp;Number</A> first.<BR>
        </FONT>
        </TD>

        <TD ALIGN="RIGHT" WIDTH="50%">
        <A HREF="http://www.sun.com"><IMG SRC="/images/lgsun.gif" width="64" height="30" border="0" ALT="Sun Microsystems, Inc."></A><BR>
        <FONT SIZE="-2" FACE="Verdana, Arial, Helvetica, sans-serif">
        Copyright &copy; 1995-99
        <A HREF="http://www.sun.com">Sun Microsystems, Inc.</A><BR>
        All Rights Reserved. 
        <a href="http://www.sun.com/share/text/SMICopyright.html">Legal Terms</a>. 
        <A HREF="http://www.sun.com/privacy/">Privacy&nbsp;Policy</A>.
        </FONT>
        </TD>
      </TR>
    </TABLE>
	
    </TD>
  </TR> 
</TABLE>
</FORM>

<!-- End Copyright Insert -->


</BODY>
</HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -