work guide for tgmc1

Upload: krishnendu-rarhi

Post on 05-Apr-2018

224 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/31/2019 Work Guide for Tgmc1

    1/157

  • 7/31/2019 Work Guide for Tgmc1

    2/157

    First, installation of IBM Java

    1.4.2

    --TGMC workshop team, SOC.

  • 7/31/2019 Work Guide for Tgmc1

    3/157

  • 7/31/2019 Work Guide for Tgmc1

    4/157

  • 7/31/2019 Work Guide for Tgmc1

    5/157

  • 7/31/2019 Work Guide for Tgmc1

    6/157

  • 7/31/2019 Work Guide for Tgmc1

    7/157

  • 7/31/2019 Work Guide for Tgmc1

    8/157

  • 7/31/2019 Work Guide for Tgmc1

    9/157

  • 7/31/2019 Work Guide for Tgmc1

    10/157

  • 7/31/2019 Work Guide for Tgmc1

    11/157

  • 7/31/2019 Work Guide for Tgmc1

    12/157

    Second, an easy installation of

    Eclipse 3.1.2 with WAS CE patched

    plug-in

    --TGMC workshop team, SOC.

  • 7/31/2019 Work Guide for Tgmc1

    13/157

  • 7/31/2019 Work Guide for Tgmc1

    14/157

  • 7/31/2019 Work Guide for Tgmc1

    15/157

  • 7/31/2019 Work Guide for Tgmc1

    16/157

  • 7/31/2019 Work Guide for Tgmc1

    17/157

    Third, Installation of WAS CE

    --TGMC workshop team, SOC.

  • 7/31/2019 Work Guide for Tgmc1

    18/157

  • 7/31/2019 Work Guide for Tgmc1

    19/157

  • 7/31/2019 Work Guide for Tgmc1

    20/157

  • 7/31/2019 Work Guide for Tgmc1

    21/157

  • 7/31/2019 Work Guide for Tgmc1

    22/157

  • 7/31/2019 Work Guide for Tgmc1

    23/157

  • 7/31/2019 Work Guide for Tgmc1

    24/157

  • 7/31/2019 Work Guide for Tgmc1

    25/157

  • 7/31/2019 Work Guide for Tgmc1

    26/157

  • 7/31/2019 Work Guide for Tgmc1

    27/157

  • 7/31/2019 Work Guide for Tgmc1

    28/157

    Last in installation, DB2 Express

    c 9.0

    --Rajaraman Srinivasan

  • 7/31/2019 Work Guide for Tgmc1

    29/157

    Choose Install a

    Product

  • 7/31/2019 Work Guide for Tgmc1

    30/157

    Choose Install New

  • 7/31/2019 Work Guide for Tgmc1

    31/157

  • 7/31/2019 Work Guide for Tgmc1

    32/157

  • 7/31/2019 Work Guide for Tgmc1

    33/157

    Choose Typical, since

    only basic features are

    included in the CD

  • 7/31/2019 Work Guide for Tgmc1

    34/157

    Remember thispath

  • 7/31/2019 Work Guide for Tgmc1

    35/157

  • 7/31/2019 Work Guide for Tgmc1

    36/157

    Remember this

    password

  • 7/31/2019 Work Guide for Tgmc1

    37/157

  • 7/31/2019 Work Guide for Tgmc1

    38/157

  • 7/31/2019 Work Guide for Tgmc1

    39/157

    Remember thispath

  • 7/31/2019 Work Guide for Tgmc1

    40/157

  • 7/31/2019 Work Guide for Tgmc1

    41/157

  • 7/31/2019 Work Guide for Tgmc1

    42/157

  • 7/31/2019 Work Guide for Tgmc1

    43/157

  • 7/31/2019 Work Guide for Tgmc1

    44/157

  • 7/31/2019 Work Guide for Tgmc1

    45/157

  • 7/31/2019 Work Guide for Tgmc1

    46/157

    If you need, you could create a sample

    database. Or, you could create your own

    database from First Steps (this window)

    Or you could launch Control Center and

    create your own database from there

  • 7/31/2019 Work Guide for Tgmc1

    47/157

    Control Center could be launched either

    from Taskbar (Right Corner) or from

    ProgramsIBM DB2 DB2COPY1

    General Administration Tools

    ControlCenter

  • 7/31/2019 Work Guide for Tgmc1

    48/157

  • 7/31/2019 Work Guide for Tgmc1

    49/157

  • 7/31/2019 Work Guide for Tgmc1

    50/157

    Enter the name of the database here

  • 7/31/2019 Work Guide for Tgmc1

    51/157

    No Input needed in this page Just click

    Next

  • 7/31/2019 Work Guide for Tgmc1

    52/157

    Choose IBM-1252

    (default option) if

    you are using the

    database to storeonly English If you

    want localization

    choose UTF-8

    Click Next

  • 7/31/2019 Work Guide for Tgmc1

    53/157

    Click on Show

    Command to see the

    database creation

    command generated

    by Control Center

    Click Finish to create

    database

  • 7/31/2019 Work Guide for Tgmc1

    54/157

    Click on Show

    Command to see the

    database creation

    command generated

    by Control Center

    Click Finish to create

    database

  • 7/31/2019 Work Guide for Tgmc1

    55/157

  • 7/31/2019 Work Guide for Tgmc1

    56/157

  • 7/31/2019 Work Guide for Tgmc1

    57/157

  • 7/31/2019 Work Guide for Tgmc1

    58/157

  • 7/31/2019 Work Guide for Tgmc1

    59/157

    No Inputs needed

    on this page Click

    Next

  • 7/31/2019 Work Guide for Tgmc1

    60/157

    No Inputs needed

    on this page Click

    Next

  • 7/31/2019 Work Guide for Tgmc1

    61/157

    Click on Add Primary

    to add a primary key

    for the table.

    Similarly for Add

    Unique and Add

    Foreign (if needed)

  • 7/31/2019 Work Guide for Tgmc1

    62/157

    No Inputs needed

    on this page Click

    Next

  • 7/31/2019 Work Guide for Tgmc1

    63/157

    Click on Add to

    impose a check

    constraint (if

    needed)

    Click on Next to

    proceed

  • 7/31/2019 Work Guide for Tgmc1

    64/157

    Click on Show SQL to

    see the table

    creation command

    generated by

    Control Center

    Click Finish to create

    table

  • 7/31/2019 Work Guide for Tgmc1

    65/157

    Click on Query to run

    queries insert, select,

    update or delete

  • 7/31/2019 Work Guide for Tgmc1

    66/157

  • 7/31/2019 Work Guide for Tgmc1

    67/157

    Configuration of Installed Softwares

    and a deep introduction to J2EE

    --TGMC workshop team, SOC.

  • 7/31/2019 Work Guide for Tgmc1

    68/157

    Give a suitable workspace here, where all your work will be

    Stored!

  • 7/31/2019 Work Guide for Tgmc1

    69/157

    Click the arrow like icon

  • 7/31/2019 Work Guide for Tgmc1

    70/157

    Click window option in the menu bar

  • 7/31/2019 Work Guide for Tgmc1

    71/157

  • 7/31/2019 Work Guide for Tgmc1

    72/157

  • 7/31/2019 Work Guide for Tgmc1

    73/157

  • 7/31/2019 Work Guide for Tgmc1

    74/157

    Right click here

  • 7/31/2019 Work Guide for Tgmc1

    75/157

  • 7/31/2019 Work Guide for Tgmc1

    76/157

    Click next after selections are made as shown

  • 7/31/2019 Work Guide for Tgmc1

    77/157

    Click next

  • 7/31/2019 Work Guide for Tgmc1

    78/157

    Click browse button, to choose the home directory where WAS CE is installed

    i.e., the parent-directory for the bin folder of WAS CE

    The error symbol

    should disappear to a

    warning symbol after

    choosing the correctlocation

  • 7/31/2019 Work Guide for Tgmc1

    79/157

    Choose the home directory and press OK

  • 7/31/2019 Work Guide for Tgmc1

    80/157

    As the correct path is

    given, the symbolchanges as shown

  • 7/31/2019 Work Guide for Tgmc1

    81/157

    Click next. Please note the user id and password for

    WAS CE

  • 7/31/2019 Work Guide for Tgmc1

    82/157

    Click finish!

  • 7/31/2019 Work Guide for Tgmc1

    83/157

    Right click the Dynamic

    web project as shown

  • 7/31/2019 Work Guide for Tgmc1

    84/157

    Make similar selections and it will

    Guide you to the project creation

    Wizard

  • 7/31/2019 Work Guide for Tgmc1

    85/157

    Give an

    appropriate

    name for yourproject and click

    next

  • 7/31/2019 Work Guide for Tgmc1

    86/157

  • 7/31/2019 Work Guide for Tgmc1

    87/157

    Click next!

  • 7/31/2019 Work Guide for Tgmc1

    88/157

    Click finish

  • 7/31/2019 Work Guide for Tgmc1

    89/157

  • 7/31/2019 Work Guide for Tgmc1

    90/157

    You should have such hierarchy

    Of files inside your dynamic web

    Projects node in the tree shown in

    Project Explorer Pane

  • 7/31/2019 Work Guide for Tgmc1

    91/157

    Right click the server

  • 7/31/2019 Work Guide for Tgmc1

    92/157

    Click start

  • 7/31/2019 Work Guide for Tgmc1

    93/157

    Wait until the server finishes starting

    You can see a message in the console!

    [it happens sometimes that the server

    Has some problems due to internet connection(wi-fi). So, disable wi-fi, if your server throws

    Exceptions at startup.]

  • 7/31/2019 Work Guide for Tgmc1

    94/157

    Now server is ready to work

  • 7/31/2019 Work Guide for Tgmc1

    95/157

    In the server pane also, the status will be started

  • 7/31/2019 Work Guide for Tgmc1

    96/157

    Click this button, to

    open web browser

  • 7/31/2019 Work Guide for Tgmc1

    97/157

    Type the address as

    shown

  • 7/31/2019 Work Guide for Tgmc1

    98/157

  • 7/31/2019 Work Guide for Tgmc1

    99/157

    Click the database

    pools link

  • 7/31/2019 Work Guide for Tgmc1

    100/157

    Click this link(first one)

    This is for creating a link

    with the Database created

    at DB2

  • 7/31/2019 Work Guide for Tgmc1

    101/157

    Give a name(and remember it) for the database pool you are creating.

    FYI: a pool is a set of connections with the database. It avoids the program

    To communicate with the database directly for accessing it each time.

    Instead, by creating this pool, it gets a set of connections from the database

    so that they can be used one-at-a-time basis, whenever needed.

    This not only saves time for the program, but also for the database!

  • 7/31/2019 Work Guide for Tgmc1

    102/157

    Select DB2 for database type, as shown, and click next

  • 7/31/2019 Work Guide for Tgmc1

    103/157

    This page requires all

    fields to be filled

    correctly.

  • 7/31/2019 Work Guide for Tgmc1

    104/157

    From the drivers

    list, choose

    com.ibm.db2/db2j

    cc/8.2/jar

    The name of the database is

    testdb in our case, and a snapshot

    f h l l h

  • 7/31/2019 Work Guide for Tgmc1

    105/157

    This is

    50000

    bydefault

    Give the database name correctly as itis the one you are going to make

    transactions through the program. The

    database should already exist and

    should be running(at least before

    testing the connection)

    of the control center is also shown

  • 7/31/2019 Work Guide for Tgmc1

    106/157

    If you see this

    message, leave

    the fields as such

    and click theTest

    Connection

    button

  • 7/31/2019 Work Guide for Tgmc1

    107/157

    Now, the server is connected with

    the database and we can deploy

    the pool permanently.

    Click Deploy

  • 7/31/2019 Work Guide for Tgmc1

    108/157

  • 7/31/2019 Work Guide for Tgmc1

    109/157

    The pool we created should appear in the list shown.

  • 7/31/2019 Work Guide for Tgmc1

    110/157

    Also, the message of successful deployment should be seen on the

    console.

  • 7/31/2019 Work Guide for Tgmc1

    111/157

    Now, to connect the pool with our application,

    Click usage link to the right of the pool, which

    has connections with the needed database

    The next page has a picture, which is the screen shot of the page that appears after

    li ki th li k f th d t b l

  • 7/31/2019 Work Guide for Tgmc1

    112/157

    clicking the usage link of the database pool.

    It also has a clipped image of the project explorer pane of eclipse with the web content

    folder of the project expanded

    You can find two sub folders within it. Among which WEB-INF has two files.Those two files are needed to be modified, in order to make our application communicate

    with the pools, which in turn communicate with the database.

    Let us look at the changes to be made.

  • 7/31/2019 Work Guide for Tgmc1

    113/157

  • 7/31/2019 Work Guide for Tgmc1

    114/157

    Copy this

    selection and

    paste it into the

    source of

    Geronimo-

    web.xml

  • 7/31/2019 Work Guide for Tgmc1

    115/157

    Pasting alone will leadto error at the

    tag

  • 7/31/2019 Work Guide for Tgmc1

    116/157

    To rectify the error, change the nam shown in the highlight to naming

  • 7/31/2019 Work Guide for Tgmc1

    117/157

    And change MyDataSource to yourpool name, as shown

  • 7/31/2019 Work Guide for Tgmc1

    118/157

  • 7/31/2019 Work Guide for Tgmc1

    119/157

  • 7/31/2019 Work Guide for Tgmc1

    120/157

    Similar changes are to be

    made for web.xml also

  • 7/31/2019 Work Guide for Tgmc1

    121/157

  • 7/31/2019 Work Guide for Tgmc1

    122/157

  • 7/31/2019 Work Guide for Tgmc1

    123/157

  • 7/31/2019 Work Guide for Tgmc1

    124/157

  • 7/31/2019 Work Guide for Tgmc1

    125/157

    Now, we shall see, how to code in eclipse, retrieve data from DB2 and

    test-and-run it in WAS CE.

  • 7/31/2019 Work Guide for Tgmc1

    126/157

    FYI: All packages needed should be placed inside the src folder

    for its usage as beans or as importable classes.All jsp,html pages should be placed inside the WebContent

    folder. In order to make a html page, right click WebContent

    and make selections as shown.

  • 7/31/2019 Work Guide for Tgmc1

    127/157

    Give a name and click next

  • 7/31/2019 Work Guide for Tgmc1

    128/157

    Click finish

  • 7/31/2019 Work Guide for Tgmc1

    129/157

    You can type the html codes here, save it.

    The sample, we are having has the following objectives:

    1. Gets the user id and password from user through a html page

    2. Verifies it with the data stored in the database and3. Finally direct the right user to welcome screen and others back to

    Login

    The values of

    i t i thi f

  • 7/31/2019 Work Guide for Tgmc1

    130/157

    inputs in this form

    will lead the page

    mentioned in its

    action property. If

    the page

    mentioned is not

    found, WAS CE

    reports error

  • 7/31/2019 Work Guide for Tgmc1

    131/157

    Now, to run the page,

    right click the file on the project

    explorer pane and select the

    options as shown.

  • 7/31/2019 Work Guide for Tgmc1

    132/157

    Click next. After

    selecting this

  • 7/31/2019 Work Guide for Tgmc1

    133/157

    Make sure that the project

    in which the file to run

    exist in the list of

    configured projects and

    click finish

  • 7/31/2019 Work Guide for Tgmc1

    134/157

  • 7/31/2019 Work Guide for Tgmc1

    135/157

  • 7/31/2019 Work Guide for Tgmc1

    136/157

    As we dont have any log.jsp, this error is reported!

  • 7/31/2019 Work Guide for Tgmc1

    137/157

    Now, create a jsp page.

  • 7/31/2019 Work Guide for Tgmc1

    138/157

  • 7/31/2019 Work Guide for Tgmc1

    139/157

  • 7/31/2019 Work Guide for Tgmc1

    140/157

    The following two slides shows the codes in this page as snapshots.

    To understand it, the forthcoming pages at the last will consist of

    Explanations to each necessary statement.

  • 7/31/2019 Work Guide for Tgmc1

    141/157

  • 7/31/2019 Work Guide for Tgmc1

    142/157

  • 7/31/2019 Work Guide for Tgmc1

    143/157

    // // //

    Hai!

    Here, the first few lines are taken. tag needs attention for the last import

    property. As value(s) for the property you can give any number of valid java packages,separated by commas. The pageEncoding field can be changed to any encoding schemes

    like UTF-8,UTF-16 etc.

    tag plays importance only in case of using XML. We can apply particular style for

    custom tags using XSLs in XML. It can be ignored right now.

    Next is the tag, within which the is used to display the text at the title bar of

    the browser.

    function fun()

    {

  • 7/31/2019 Work Guide for Tgmc1

    144/157

    {

    alert("welcome user!your details are found in the database!!");

    }

    function foon()

    {

    alert("Sorry! you are not a valid user!! click here to go back to login!!!");

    history.back(1);

    }

    The power of J2EE lies in the use of HTML, java, JavaScript, XML etc. in a single source file.

    This shows two javascript functions with the output of fun() as shown in (i) and foon()

    produces the message as shown in(ii) and leads to the page visited before.

    (i) (ii)

  • 7/31/2019 Work Guide for Tgmc1

    145/157

  • 7/31/2019 Work Guide for Tgmc1

    146/157

    boolean flag=false;

    InitialContext ic=new InitialContext();

    DataSource ds=(DataSource)ic.lookup("java:comp/env/jdbc/testpool");Connection con=ds.getConnection();

    Statement stmt=con.createStatement();

    For simplicity, it is not necessary to understand ever line of this jdbc block.These are the statements for making connection with the pool. These statements need

    Javax.naming.*, javax.sql.*, java.sql.* ;

    boolean flag=false;

    is a statement to be used to indicate the validity of the users login.

    In the 5 th line, the testpool should be replaced by the appropriate pool names given in

    the WEB-INF/web.xml and WEB_INF/geronimo-web.xml files.Statement is a class, which has methods for executing queries and it cannot be directly

    instantiated.

    The first statement try{ will be referred in slide 82.

    ResultSet rs=stmt.executeQuery("select * from log_table");

    while(rs.next())

    {

  • 7/31/2019 Work Guide for Tgmc1

    147/157

    {

    String temp=rs.getString(1);

    String temp1=rs.getString("pass");

    if(temp.equals(user)&&temp1.equals(pas))

    {

    flag=true;

    break;

    }

    }

    To execute select queries, we use stmt.executeQuery() whose result is returned in a ResultSet

    object. Insert, update & delete queries should be executed as stmt.executeUpdate(query);

    From the ResultSet object , we should know about 2 general functions. next() function takes

    the cursor to the next row of the result and returns true on success and if it is already in the

    last row, returns false. get() method returns the cell value specified by the column namas String or column index as integer with the specified type.

    The logic involves checking the user id and password entered with those retrieved from the

    log_table in the database.

    if(flag)

    {

    out.println("hai!!!"+user);

    %>

  • 7/31/2019 Work Guide for Tgmc1

    148/157

    %>

    fun();

    document.write("Invalid parameters");

    foon();

  • 7/31/2019 Work Guide for Tgmc1

    149/157

    {

    e.printStackTrace();

    }%>

    Every try{} block should have a catch(){} block or finally{} block or both. As java is very cryptic

    In errors and exceptions it is necessary to use them. However J2EE has a choice.

    But to keep track of errors, it is advised to use try blocks wherever needed.

    The statement e.printStackTrace(); will have references to the line in which the error occurred

    by showing a lengthy stack trace at the servers console, which will help in debugging.

    Finally, the code is to be tested and run.

    As seen, this page needs the sample.html page to be run, in order to check for bugs.

    So, run sample.html.

  • 7/31/2019 Work Guide for Tgmc1

    150/157

  • 7/31/2019 Work Guide for Tgmc1

    151/157

  • 7/31/2019 Work Guide for Tgmc1

    152/157

  • 7/31/2019 Work Guide for Tgmc1

    153/157

  • 7/31/2019 Work Guide for Tgmc1

    154/157

  • 7/31/2019 Work Guide for Tgmc1

    155/157

  • 7/31/2019 Work Guide for Tgmc1

    156/157

  • 7/31/2019 Work Guide for Tgmc1

    157/157