how the db connection is done in this peice of code
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: how the db connection is done in this peice of code

  1. #1
    Join Date
    Sep 2002
    Location
    hyderabad
    Posts
    2

    how the db connection is done in this peice of code

    dear sir,
    i have to important question.

    i am pasting the code of a jsp file below.... please look in to this...

    in this page.. how is he making a database connection... and in this page
    where are the select statements and queries.... i have tried many times reading
    this ..but i could not find the queries ..not even any one.

    if anyone sees this jsp file also ... he will not be able to see the queries.
    can u please help me .. how to do this type of connection and also how to use queries
    like select insert and delete and update .

    an example will help me out...please help me...

    Ramesh

    the file is below....


    <%@ include file="jtfincl.jsp" %>

    <%@ page language="java" %>
    <%@ page import="oracle.apps.ibu.common.IBUContext" %>
    <%@ page import="oracle.apps.ibu.common.IbuException" %>
    <%@ page import="oracle.apps.ibu.common.Employee" %>
    <%@ page import="oracle.apps.ibu.common.EmployeeInfo" %>
    <%@ page import="oracle.jdbc.driver.*" %>
    <%@ page import="oracle.apps.jtf.aom.transaction.*" %>
    <%@ page import="oracle.apps.jtf.base.resources.*" %>
    <%@ page import="oracle.apps.jtf.base.interfaces.MessageManagerInter"%>
    <%@ page import="oracle.apps.ibu.registration.IbuRegistration" %>
    <%@ page import="oracle.apps.ibu.registration.CustomerVO" %>
    <%@ page import="oracle.apps.ibu.common.IDNamePair" %>
    <%@ page import="oracle.apps.ibu.common.*" %>
    <%@ page import="oracle.apps.ibu.registration.*" %>
    <%@ page import="java.math.BigDecimal" %>


    <jsp:useBean id = "_displayManager"
    class = "oracle.apps.ibu.common.DisplayManager"
    scope = "application" />

    <jsp:useBean id = "ibuPromptManager"
    class = "oracle.apps.ibu.common.PromptManager"
    scope = "application" />

    <%
    String appName= "IBU";
    boolean stateless=true; // used for jtfsrfp.jsp
    SiteProperty.load();
    String username = SiteProperty.getGuestUsername();
    String password = SiteProperty.getGuestPassword();
    %>


    <%@ include file="jtfsrfp.jsp" %>

    <%
    String forwardURL = null;
    String backURL = null;
    String emailAddress = null;
    long employeeID = -1;

    String submitType = (String) request.getParameter("submitType");

    IBUContext _context = new IBUContext(_fwSession);

    String errorKey = "";
    String errorMessage = "";
    String errorStack = "";

    boolean currentStatus = true;

    Object lockx = new Object ();
    OracleConnection conn = null;
    try
    {
    TransactionScope.begin(lockx);
    try
    {
    conn = (OracleConnection)
    TransactionScope.getConnection();
    }
    catch ( Exception e )
    {
    throw new FrameworkException("Error getting connection..");
    }
    if ( conn == null )
    {
    throw new FrameworkException("Error getting connection..");
    }

    String<> textMsgs = new String<3>;
    MessageManagerInter msgMgr = Architecture.getMessageManagerInstance();
    textMsgs<0> = msgMgr.getMessage("IBU_RG_CONTRACT24");
    //textMsgs<0> = " is not a valid employee email address.";
    textMsgs<1> = msgMgr.getMessage("IBU_RG_CONTRACT25");
    //textMsgs<1> = " Cannot get the employee id.";
    textMsgs<2> = msgMgr.getMessage("IBU_RG_CONTRACT13");
    //textMsgs<2> = "submitType is null, please check program.";

    if ( (submitType != null) && "LOGIN".equals( submitType ) )
    {
    forwardURL="jtflogin.jsp";
    backURL="jtflogin.jsp";
    }
    else if ( (submitType != null) && "EMPLOYEE_CHECK".equals( submitType ) )
    {
    forwardURL="ibuemplcheck.jsp";
    backURL="ibuemplcheck.jsp";
    }
    else if ( (submitType != null) && "EMPLOYEE_NUMBER_SUBMIT".equals( submitType ) )
    {
    backURL="ibuemplcheck.jsp";
    emailAddress = (String) request.getParameter("emailAddress");
    pageContext.setAttribute("emailAddress", emailAddress , PageContext.REQUEST_SCOPE);
    employeeID = IbuRegistration.getEmployeeID(conn,emailAddress);
    if (employeeID == -1)
    {
    throw new IbuRegException(emailAddress + " "+textMsgs<0> + " " +textMsgs<1>);
    }
    //validate employee
    currentStatus = Employee.isValidate(conn,emailAddress);
    //currentStatus = IbuRegistration.isEmployeeValid(conn,emailAddress);
    if (!currentStatus)
    {
    throw new IbuRegException(emailAddress + " " + textMsgs<0>);
    }
    /*
    EmployeeInfo employee = Employee.findEmployee(conn,employeeID);
    pageContext.setAttribute("employee", employee , PageContext.REQUEST_SCOPE);
    pageContext.setAttribute("employeeIDStr", Long.toString(employeeID) , PageContext.REQUEST_SCOPE);
    */
    forwardURL="ibuemplinput.jsp";
    }
    else
    { // Cancel button was pressed
    throw new IbuRegException(textMsgs<2>);
    /* "ibuccsii.jsp"; */
    }
    }
    catch ( IbuException e )
    {
    TransactionScope.setRollbackOnly();
    errorMessage = e.getMessage();
    errorStack = IbuRegException.getStack(e);
    pageContext.setAttribute("errorMessage", errorMessage , PageContext.REQUEST_SCOPE);
    pageContext.setAttribute("errorStack", errorStack , PageContext.REQUEST_SCOPE);
    forwardURL = backURL;
    }
    catch (IbuRegException e)
    {
    TransactionScope.setRollbackOnly();
    errorMessage = e.getMessage();
    errorStack = e.getStack();
    pageContext.setAttribute("errorMessage", errorMessage , PageContext.REQUEST_SCOPE);
    pageContext.setAttribute("errorStack", errorStack , PageContext.REQUEST_SCOPE);
    forwardURL = backURL;
    }
    catch ( Exception e )
    {
    TransactionScope.setRollbackOnly();
    errorMessage = e.getMessage();
    errorStack = IbuRegException.getStack(e);
    pageContext.setAttribute("errorMessage", errorMessage , PageContext.REQUEST_SCOPE);
    pageContext.setAttribute("errorStack", errorStack , PageContext.REQUEST_SCOPE);
    forwardURL = backURL;
    //throw new FrameworkException( e , "IBU_UNEXPECTED_EXCEPTION");
    }
    finally
    {
    TransactionScope.releaseConnection( conn );
    TransactionScope.end ( lockx );
    }
    if (forwardURL == null)
    {
    forwardURL="jtflogin.jsp";
    }

    %>
    <jsp:forward page= "<%= forwardURL %>" />

    <%@ include file="jtferlp.jsp" %>

  2. #2
    Join Date
    May 2001
    Posts
    594

    Oracle specific

    The creator of the code you post is using Oracle specific libraries. The creation of the Connection appears to be hidden behind a static method in TransactionScope.
    Which I assume is in: oracle.apps.jtf.aom.transaction.

    The SQL statements are hidden in classes such as Employee and IbuRegistration. Anything which is passed the 'conn' variable.

    The JSP is showing a form of MVC structure. Your JSP file is a C/Controller, it's forwarding to a series of V/Views, and the M/Model is all the methods that are being passed 'conn' to get data.

    In reality, there would appear to be some major issues in the code below. It is Oracle specific [I don't know enough about the libraries in question to know if there is a reason for being Oracle specific or if it is just marketing. I suspect the latter]. It is desperately in need of using JNDI and a DataSource for its connection, which removes and standardises all of the database code.
    It seems more painful than it should be

    The code also has <1> and stuff in. ie) angled brackets. I don't know if this is your code or the message board system, but they should be square brackets, ie) [1].
    Bayard
    bayard@generationjava.com
    http://www.apache.org/~bayard
    http://www.generationjava.com

    Brainbench MVP for Java
    http://www.brainbench.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center