IBM-DB2 and Worklight Connectivity

download IBM-DB2 and Worklight Connectivity

of 4

description

IBM-DB2 and Worklight Connectivity

Transcript of IBM-DB2 and Worklight Connectivity

  • BHUVANESWARAN B / AP (SS) / CSE / REC - 10

    IBM DB2 Worklight Connectivity

    App to display the Details from an existing table 1. Open Eclipse 2. Select the Workspace. 3. Select File New Worklight Project 4. Enter the project name as Student. 5. Select the Project template as Hybrid Application. 6. Click Next. 7. Enter the Application Name as Student. 8. Select Add jQuery Mobile. 9. Select the location of the jQuery (jquery.mobile-1.3.0 folder) files. 10. Select css, images and jss folder. 11. Click Finish. 12. Select adapters. 13. Right click and select New Worklight Adpapter. 14. Select the Adapter type as SQL Adapter. 15. Enter the name as Students. 16. Check the Create procedures for offline JSONStore. 17. Click Finish. 18. Open the folder:

    C:\Program Files\IBM\SQLLIB\java 19. Copy the following two files:

    db2jcc.jar db2jcc_license_cu.jar

    20. Paste into server lib in the project explorer.

  • BHUVANESWARAN B / AP (SS) / CSE / REC - 11

    21. Open the Student.xml from the Student adapter. 22. Change the following:

    com.mysql.jdbc.Driver jdbc:mysql://localhost:3306/mydb myPassword

    myPassword 23. Into:

    com.ibm.db2.jcc.DB2Driver jdbc:db2://localhost:50000/rec bhuvan gates

    24. Open the Student-impl.js from the Student adapter. 25. Change the following code: var selectStatement = WL.Server.createSQLStatement("select COLUMN1, COLUMN2 from TABLE1"); function getStudents() { return WL.Server.invokeSQLStatement({ preparedStatement : selectStatement, parameters : [] }); } 26. Into: var selectStatement = WL.Server.createSQLStatement("select * from student"); function getStudents() { return WL.Server.invokeSQLStatement({ preparedStatement : selectStatement, parameters : [] }); } 27. Select the Student adapter. 28. Right click and choose Run As Invoke Worklight Procedure. 29. Select the procedure name as getStudents and click Run. 30. It will open a browser containing all the records from the table. 31. Select the Student.html file from apps Student Common. 32. Double click and open the same.

  • BHUVANESWARAN B / AP (SS) / CSE / REC - 12

    33. Select Source and remove the text Student.

    Student

    34. Switch to Design view. 35. Drag and drop a Header and change it as Rajalakshmi Engg. College by double clicking

    it. 36. Drag and drop a Button into the widget and change it as Show Name List. 37. Add the following code in the head section.

    function loadSQLRecords(){ var invocationData = { adapter : 'Student', procedure : 'getStudents', parameters : [] }; WL.Client.invokeProcedure(invocationData,{ onSuccess : loadSQLQueerySuccess, onFailure : loadSQLQueeryFailure });

    }

    function loadSQLQueerySuccess(result){ WL.Logger.debug("Retrieve success" + JSON.stringify(result)); displayFeeds(result.invocationResult.resultSet);

    }

    function loadSQLQueeryFailure(result){ WL.Logger.error("Retrieve failure");

    }

    function displayFeeds(items){ var ul = $('#itemsList'); for (var i = 0; i < items.length; i++) { var li = $('').html(items[i].ROLLNO); li.append($('').html(items[i].SNAME)); li.append($('').html(items[i].BRANCH)); li.append($('')); ul.append(li);

    } }

    38. Add the following code:

  • BHUVANESWARAN B / AP (SS) / CSE / REC - 13

    39. Change the Button element as below: Show Name List 40. Add a Worklight Environment. 41. Build All and Deploy. 42. In the Browser Simulator click Show Name List.