Loose coupling. When you use JDBC, you're saying "I'm going to use a
relational database," and typically adding "What's more, I'm going to use
THIS relation database," when you consider how people are using SQL (with
mysql/oracle/postgres specific SQL commands, for example.)
EJBs remove the data access mechanism and focus on the data itself. One
person might populate a table by the following pseudocode:
establish connection via JDBC
build preparedstatement
establish parameters
run query
while(resultset has more data)
add to table with current record
close connection
While someone else might do it this way:
establish JNDI context (roughly analogous to JDBC connection, but more
generic)
get home interface of EJB (establishes type of data)
get collection of relevant data
while(list has more data)
add to tabel with current object
There's no SQL here for the EJB user to write; he/she just says something
like
List myData=peopleHome.findByLastName("s%");
and that gets resolved (to SQL, most likely, but not necessarily) by the EJB
container. The JSP writer doesn't write any SQL code; the EJB deployer does.
Of course, this highlights the primary flaw in J2EE: the plethora of roles,
often played by the same person, and the lack of awareness of it. When I
deploy a J2EE app, I'm the front end designer, the front end deployer, the
front end admin (a light load indeed!), the ejb developer, the ejb
deployer...
To answer someone else's direct question to me, you can use tags to do this
too. For example:
<table>
<ejb:useHome
id="personHome"
type="com.es.ejb.person.personHome"
location="String" />
<ejb:iterate
id="person"
type="com.es.ejb.person.Person"
collection="<%= personHome.findByLastName(lastName) %>" >
<tr>
<td>
<jsp:getProperty name="person" property="id" />
</td>
<td>
<jsp:getProperty name="person" property="lastname" />
</td>
</tr>
</ejb:iterate>
</table>
(This is done with Orion's ejb taglib, which can be found at
http://www.orionserver.com/)
>From: Roland Dong <[EMAIL PROTECTED]>
>Reply-To: A mailing list about Java Server Pages specification and
> reference <[EMAIL PROTECTED]>
>To: [EMAIL PROTECTED]
>Subject: Re: using "like" statement wih preparedStatement
>Date: Thu, 8 Feb 2001 23:00:43 -0800
>
>Just wondering why EJBs are much preferred to JDBC? Can you give an
>example?
>
>Roland
>
>You can use "like" in a prepared statement; as I recall, all you'd need is
>to make sure the string you're setting has the wildcards. To wit:
>
>PreparedStatement ps=connection.createPreparedStatement(
> "select * from products where name like ?");
>ps.setString(1, "%"+searchName+"%");
>
>I've not tested that code, and I don't usually use JDBC directly any more
>(EJBs much preferred) so you may have to tweak some.
>
>===========================================================================
>To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
>JSP-INTEREST".
>For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
>DIGEST".
>Some relevant FAQs on JSP/Servlets can be found at:
>
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.html
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets