×

Good News Everybody!

The new search engine is LIVE!

Please report any problems to david (at) midrange.com.




I have been unable to find an example of using either row sets or data
access JavaBeans for DB2/400.  Everything I find, (including IBM illustrates
using DB2 for the PC). I have an WebSphere 3.5 application I want to use
these methods for database access but I am having trouble converting the DB2
examples to DB2/400.  Specifically, the DB2 examples build a
StatementMetaData object using the metaData.addParameter and
metaData.addColumn methods to build the SQL statement.  Finally the example
performs a metaData.addTable method.

Here is an excerpt of the example I downloaded from IBM's Websphere site for
using data access JavaBeans

public void init (ServletConfig config) throws SevletException {
try {
        Hashtable parms = new Hashtable();
        parms.put(Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.ejs.ns.jndi.CNInitialContextFactory");
        Context ctx = new InitialContext(parms);

        ds = (DataSource) ctx.lookup(source);
}
catch (Exception e) {}

//Add data access JavaBeans code

String sqlQuery = "SELECT ID, NAME, DEPT, COMM FROM " owner.toUpperCase() +
".STAFF" + "WHERE ID >= ? AND DEPT = ? ORDER BY ID ASC";

metaData = new StatementMetaData();
metaData.setSQL(sqlQuery);

try {
        metaData.addParameter("idParm",         Integer.class,
Types.SMALLINT);
        metaData.addParameter("deptParm",       String.class,
Types.SMALLINT);
        metaData.addColumn("ID",                String.class,
Types.SMALLINT);
        metaData.addColumn("NAME",              String.class,
Types.VARCHAR);
        metaData.addColumn("DEPT",              Integer.class,
Types.SMALLINT);
        metaData.addColumn("COMM",              BigDecimal.class,
Types.Decimal);
        metaData.addTable(owner.toUpperCase(), + ".STAFF");
}
catch (Exception e) {}
}

public void doGet(HttpServletRequest req, HttpServletResponse res) {

Connection conn = null;
SelectResult result = null;
DatabaseConnection dataAccessConn = null;

try {
        conn.ds.getConnection(user, password);
        dataAccessConn = new DatabaseConnection(conn);

        SelectStatement selectStatement = new SelectStatement;
        selectStatement.setConnection(dataAccessConn);

        selectStatement.setMetaData(metaData);

        selectStatement.setParameter("deptParm", (String) "42");
        selectStatement.setParameter("idParm", new Integer(100));
        selectStatement.execute();

        result = selectStatement.getResult();
        .....
Does anyone know how this would translate to DB2/400?  I know the naming
context works ok because i have used it before using a result set.  I really
would like to use the data access JavaBean.

Thanks for any suggestions.




Stephen Gibson

Lees Carpets
A Division of Burlington Industries
3330 West Friendly Avenue
Greensboro, NC 27410

Phone 336.379.2728



This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2026 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.