Comp2513 Database and E-Commerce Daniel L. Silver,  Ph.D.
Objectives <ul><li>To introduce the basic concepts of database and DBMS </li></ul><ul><li>To describe the relational datab...
Outline <ul><li>Databases and DBMS </li></ul><ul><li>Relation database </li></ul><ul><li>Structured Query Language (SQL) <...
What is a Database? <ul><li>Database - A collection of data, structured in a well defined format, accessed by multiple app...
Database Management System <ul><li>DBMS – a collection of software that facilitates and optimizes database I/O for applica...
Relational Database <ul><li>Different databases have different ways of organizing and representing data – referred to as a...
Relation DBMS - RDBMS <ul><li>Major Commercial RDBMS vendors: </li></ul><ul><ul><li>IBM (DB2) </li></ul></ul><ul><ul><li>O...
An Example: ERD ERD = Entity Relationship Diagram
An Example: Relational Tables <ul><li>pnum pdesc psd ped </li></ul><ul><ul><li>E911 Apr Nov </li></ul></ul><ul><ul><li>CAP...
SQL- Structured Query Language <ul><li>Data within a DBMS is manipulated via a 4GL or by a specific application program us...
SQL Basics <ul><li>CREATE TABLE – creates a table and defines its fields (columns), e.g.: </li></ul><ul><ul><li>CREATE TAB...
SQL Basics <ul><li>INSERT INTO – places values into a table </li></ul><ul><li>UPDATE – changes values in a table </li></ul...
An Example: Relational Tables <ul><li>pnum pdesc psd ped </li></ul><ul><ul><li>E911 Apr Nov </li></ul></ul><ul><ul><li>CAP...
SQL Select Example <ul><ul><li>Find all projects in which Jim Nasium is involved … </li></ul></ul><ul><ul><li>Set qename =...
Our E-Commerce Mall DBMS <ul><li>We are using PostgreSQL (postgres) </li></ul><ul><li>Freely available off the web </li></...
Our E-Commerce Mall DB <ul><li>Consists of 3 tables created and managed by  PostgreSQL </li></ul><ul><li>Categories </li><...
Our E-Commerce Mall DB <ul><li>Products </li></ul><ul><ul><li>product_id  int </li></ul></ul><ul><ul><li>product_name  cha...
Our E-Commerce Mall DB <ul><li>Product_category </li></ul><ul><ul><li>product_id int </li></ul></ul><ul><ul><li>category_i...
SQL and Our E-Commere  Mall Database <ul><li>From index.jsp, a java bean is used to query our E-Commerce Mall DB to get th...
SQL and Our E-Commere  Mall Database <ul><li>DETAILS: </li></ul><ul><li>From index.jsp, the following use of a java bean g...
SQL and Our E-Commere  Mall Database <ul><li>From category.jsp, a java bean is used to query our E-Commerce Mall DB to get...
SQL and Our E-Commere  Mall Database <ul><li>DETAILS: </li></ul><ul><li>From category.jsp, a java bean is used to get the ...
ODBC <ul><li>Open Database Connectivity is a widely accepted application programming interface (API) for database access d...
ODBC <ul><li>Originally, a proprietary language was used to talk to each DBMS </li></ul><ul><li>A program required unique ...
ODBC <ul><li>ODBC abstracts away specific DBMS </li></ul><ul><li>The application issues ODBS API calls </li></ul><ul><li>O...
JDBC <ul><li>Java Database Connectivity </li></ul><ul><li>JDBC is a trademark of SUN Microsystems </li></ul><ul><li>Standa...
JDBC Facilitates DB I/O <ul><li>Connect to DB and establish a session: </li></ul><ul><li>conn = StoreDatabase.getConnectio...
JDBC Facilitates DB I/O <ul><li>The executeQuery() method returns a ResultSet object that contains the results of  the que...
JDBC Facilitates DB I/O <ul><li>DETAILS of getChildren: </li></ul><ul><li>List children = new Vector(); </li></ul><ul><li>...
JSPs simplify JDBC (WS/DB2) <ul><li>Java Server Pages can make use of pre-written code to facilitate DB access </li></ul><...
JSPs simplify JDBC <ul><li>Portion of code within  index.jsp that accesses the Mall DB when displaying the categories at t...
JSPs simplify JDBC <ul><li>DETAILS: </li></ul><ul><li><% </li></ul><ul><li>int spaceWidth = 600 - (categories.size() * 110...
The Role of Database  in E-Commerce <ul><li>Database is used within E-Commerce to provide dynamic ad hoc information on-de...
Major Architectural Components of the Web Internet Browser Database Server Client 1 Server A Server B Bank Server URL HTTP...
THE END [email_address]
SQL and WebSphere <ul><li>From index.jsp, the following gets the various category names (cgname) and reference numbers for...
SQL and WebSphere <ul><li>From index.jsp, the following gets the various category names (cgname) and reference numbers for...
SQL and WebSphere <ul><li>From product.jsp, the following gets the various  </li></ul><ul><li>product category names (cgna...
SQL and WebSphere <ul><li>From productDisplay.jsp, the following gets various product values for display for specified mer...
JDBC Facilitates WS DB I/O <ul><li>Connect to DB and establish a session: </li></ul><ul><ul><li>Connection myConnection = ...
Upcoming SlideShare
Loading in...5
×

Database Fundamentals for E-Comm

486

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
486
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Database Fundamentals for E-Comm

  1. 1. Comp2513 Database and E-Commerce Daniel L. Silver, Ph.D.
  2. 2. Objectives <ul><li>To introduce the basic concepts of database and DBMS </li></ul><ul><li>To describe the relational database model </li></ul><ul><li>To discuss the Stuctured Query Language </li></ul><ul><li>To define ODBC and JDBC </li></ul><ul><li>To outline the role that database plays in E-Commerce </li></ul><ul><li>Reference: portions of Chapter 6 </li></ul>
  3. 3. Outline <ul><li>Databases and DBMS </li></ul><ul><li>Relation database </li></ul><ul><li>Structured Query Language (SQL) </li></ul><ul><li>ODBC and JDBC </li></ul>
  4. 4. What is a Database? <ul><li>Database - A collection of data, structured in a well defined format, accessed by multiple applications using standard commands, ensuring integrity of access </li></ul><ul><li>A Database can contain many records and the equivalent of many files each containing many records </li></ul>
  5. 5. Database Management System <ul><li>DBMS – a collection of software that facilitates and optimizes database I/O for applications </li></ul><ul><ul><li>Flexible access to data - independent of physical storage </li></ul></ul><ul><ul><li>Rapid response to ad hoc queries </li></ul></ul><ul><ul><li>Access by multiple applications in various ways </li></ul></ul><ul><ul><li>Ensures data integrity </li></ul></ul><ul><ul><li>Elimination of redundant data </li></ul></ul>
  6. 6. Relational Database <ul><li>Different databases have different ways of organizing and representing data – referred to as a data model </li></ul><ul><li>The relational data model – data is placed in tables where rows represent records and columns represent fields </li></ul><ul><li>Tables have no predefined relation to one another, instead data can be dynamically related </li></ul>
  7. 7. Relation DBMS - RDBMS <ul><li>Major Commercial RDBMS vendors: </li></ul><ul><ul><li>IBM (DB2) </li></ul></ul><ul><ul><li>Oracle </li></ul></ul><ul><ul><li>MS (Access, SQL Server) </li></ul></ul><ul><ul><li>INGRES (RTI) </li></ul></ul><ul><ul><li>Informix </li></ul></ul><ul><li>Freely Available RDBMS: </li></ul><ul><ul><li>PostgreSQL </li></ul></ul><ul><ul><li>MySQL </li></ul></ul>
  8. 8. An Example: ERD ERD = Entity Relationship Diagram
  9. 9. An Example: Relational Tables <ul><li>pnum pdesc psd ped </li></ul><ul><ul><li>E911 Apr Nov </li></ul></ul><ul><ul><li>CAPC Aug Dec </li></ul></ul>eid ename 9902 Ritter, Tex 0103 Nasium, Jim <ul><li>aid ……………….. </li></ul><ul><li>apnum aeid alnum abd aed </li></ul><ul><li>9902 Hfx1 May Oct </li></ul><ul><li>1 0103 Hfx1 May Aug </li></ul><ul><li>2 0103 Yrm2 Sep Oct </li></ul>lnum laddress Hfx1 1234 Barrington St. Yrm2 56 Front St. PROJECT EMPLOYEE ASSIGNMENT LOCATION
  10. 10. SQL- Structured Query Language <ul><li>Data within a DBMS is manipulated via a 4GL or by a specific application program using a DBMS access language </li></ul><ul><li>SQL is data definition and manipulation langauge for relational databases </li></ul><ul><li>SQL has become an international standard </li></ul>
  11. 11. SQL Basics <ul><li>CREATE TABLE – creates a table and defines its fields (columns), e.g.: </li></ul><ul><ul><li>CREATE TABLE PROJECT </li></ul></ul><ul><ul><ul><li>(pnum integer NOT NULL. </li></ul></ul></ul><ul><ul><ul><li>pdesc character NOT NULL. </li></ul></ul></ul><ul><ul><ul><li>PRIMARY KEY (pnum); </li></ul></ul></ul><ul><li>ALTER TABLE – delete or add fields </li></ul><ul><li>DROP TABLE – delete an entire table </li></ul>
  12. 12. SQL Basics <ul><li>INSERT INTO – places values into a table </li></ul><ul><li>UPDATE – changes values in a table </li></ul><ul><li>DELETE FROM – removes records in table </li></ul><ul><li>SELECT – columns from a table, general format: </li></ul><ul><ul><li>SELECT <colname>, <colname> FROM <tablename> WHERE <condition> </li></ul></ul>
  13. 13. An Example: Relational Tables <ul><li>pnum pdesc psd ped </li></ul><ul><ul><li>E911 Apr Nov </li></ul></ul><ul><ul><li>CAPC Aug Dec </li></ul></ul>eid ename 9902 Ritter, Tex 0103 Nasium, Jim <ul><li>aid ……………….. </li></ul><ul><li>apnum aeid alnum abd aed </li></ul><ul><li>9902 Hfx1 May Oct </li></ul><ul><li>1 0103 Hfx1 May Aug </li></ul><ul><li>2 0103 Yrm2 Sep Oct </li></ul>lnum laddress Hfx1 1234 Barrington St. Yrm2 56 Front St. PROJECT EMPLOYEE ASSIGNMENT LOCATION
  14. 14. SQL Select Example <ul><ul><li>Find all projects in which Jim Nasium is involved … </li></ul></ul><ul><ul><li>Set qename = “Nasium, Jim” </li></ul></ul><ul><ul><li>SELECT pnum, pdesc </li></ul></ul><ul><ul><li>FROM employee, assignment, project </li></ul></ul><ul><ul><li>WHERE ename = qename AND </li></ul></ul><ul><ul><li>assignment.aeid = employee.eid AND </li></ul></ul><ul><ul><li>project.pnum = assignment.apnum </li></ul></ul><ul><ul><li>Returns: </li></ul></ul><ul><li>pnum pdesc </li></ul><ul><ul><li>E911 </li></ul></ul><ul><ul><li>CAPC </li></ul></ul>
  15. 15. Our E-Commerce Mall DBMS <ul><li>We are using PostgreSQL (postgres) </li></ul><ul><li>Freely available off the web </li></ul><ul><li>What is PostgreSQL ? </li></ul><ul><li>The PostgreSQL page. </li></ul>
  16. 16. Our E-Commerce Mall DB <ul><li>Consists of 3 tables created and managed by PostgreSQL </li></ul><ul><li>Categories </li></ul><ul><ul><li>category_id int </li></ul></ul><ul><ul><li>category_name char 50 </li></ul></ul><ul><ul><li>description text </li></ul></ul><ul><ul><li>image char 100 </li></ul></ul><ul><ul><li>parent int (null if a store) </li></ul></ul>
  17. 17. Our E-Commerce Mall DB <ul><li>Products </li></ul><ul><ul><li>product_id int </li></ul></ul><ul><ul><li>product_name char 50 </li></ul></ul><ul><ul><li>sku char 50 </li></ul></ul><ul><ul><li>description text </li></ul></ul><ul><ul><li>image char 100 </li></ul></ul><ul><ul><li>price real </li></ul></ul><ul><ul><li>category int </li></ul></ul>
  18. 18. Our E-Commerce Mall DB <ul><li>Product_category </li></ul><ul><ul><li>product_id int </li></ul></ul><ul><ul><li>category_id int </li></ul></ul><ul><li>Used to display a product in more than one category </li></ul>
  19. 19. SQL and Our E-Commere Mall Database <ul><li>From index.jsp, a java bean is used to query our E-Commerce Mall DB to get the categories for a particular store: </li></ul><ul><li>(“SELECT category_id, category_name, description, image FROM category WHERE parent = ?&quot;); </li></ul><ul><li>pstmt.setInt(1,getId()); </li></ul>
  20. 20. SQL and Our E-Commere Mall Database <ul><li>DETAILS: </li></ul><ul><li>From index.jsp, the following use of a java bean gets the categories of a store: </li></ul><ul><li>List categories = store.getCategories(); </li></ul><ul><li>The getCategories method in turn uses another bean to get all categories: </li></ul><ul><li>category.getChildren() </li></ul><ul><li>The getChildren method makes the SQL query via a JDBC request: </li></ul><ul><li>conn = StoreDatabase.getConnection(); </li></ul><ul><li>pstmt = conn.prepareStatement(&quot;SELECT category_id,category_name,description,image FROM category WHERE parent = ?&quot;); </li></ul><ul><li>pstmt.setInt(1,getId()); </li></ul><ul><li>rs = pstmt.executeQuery(); </li></ul>
  21. 21. SQL and Our E-Commere Mall Database <ul><li>From category.jsp, a java bean is used to query our E-Commerce Mall DB to get the products of a particular category: </li></ul><ul><li>(&quot;SELECT product_id, product_name, sku,description, image,price FROM product WHERE category = ?&quot; + </li></ul><ul><li>&quot; OR EXISTS (SELECT * FROM product_category </li></ul><ul><li>WHERE product_category.category_id = ?&quot; + </li></ul><ul><li>&quot; AND product_category.product_id = product.product_id)&quot;); </li></ul><ul><li>pstmt.setInt(1,category.getId()); pstmt.setInt(2,category.getId()); </li></ul>
  22. 22. SQL and Our E-Commere Mall Database <ul><li>DETAILS: </li></ul><ul><li>From category.jsp, a java bean is used to get the categories of a store: </li></ul><ul><li>List products = Product.getProducts(category); </li></ul><ul><li>The getProducts method makes the SQL query via a JDBC request: </li></ul><ul><li>conn = StoreDatabase.getConnection(); </li></ul><ul><li>pstmt = conn.prepareStatement(&quot;SELECT product_id,product_name,sku,description, image,price FROM product WHERE category = ?&quot; + </li></ul><ul><li>&quot; OR EXISTS (SELECT * FROM product_category </li></ul><ul><li>WHERE product_category.category_id = ?&quot; + </li></ul><ul><li>&quot; AND product_category.product_id = product.product_id)&quot;); </li></ul><ul><li>pstmt.setInt(1,category.getId()); </li></ul><ul><li>pstmt.setInt(2,category.getId()); </li></ul><ul><li>rs = pstmt.executeQuery(); </li></ul>
  23. 23. ODBC <ul><li>Open Database Connectivity is a widely accepted application programming interface (API) for database access developed by a consortium led by MicroSoft </li></ul><ul><li>ODBC is a combination of ODBC API function calls and the SQL language </li></ul>
  24. 24. ODBC <ul><li>Originally, a proprietary language was used to talk to each DBMS </li></ul><ul><li>A program required unique code to interact with Access, DB2 and Oracle databases </li></ul>Program with 3 different sets of API calls and SQL Oracle DB Oracle DBMS DB2 DB DB2 DBMS Access DB Access DBMS
  25. 25. ODBC <ul><li>ODBC abstracts away specific DBMS </li></ul><ul><li>The application issues ODBS API calls </li></ul><ul><li>ODBC Manager interfaces with the target DBMS </li></ul><ul><li>ODBC driver must be installed for each DBMS </li></ul>ODBC Manager Oracle DB Oracle DBMS DB2 DB DB2 DBMS Access DB Access DBMS Program with ODBC API calls and SQL
  26. 26. JDBC <ul><li>Java Database Connectivity </li></ul><ul><li>JDBC is a trademark of SUN Microsystems </li></ul><ul><li>Standard API that lets you access virtually any tabular data source from Java programs </li></ul><ul><ul><li>relational databases, flat files, spreadsheet files </li></ul></ul><ul><li>JDBC builds on and reinforces the style and virtues of Java (easy to use) </li></ul>
  27. 27. JDBC Facilitates DB I/O <ul><li>Connect to DB and establish a session: </li></ul><ul><li>conn = StoreDatabase.getConnection(); </li></ul><ul><li>… within getConnection … </li></ul><ul><li>Connection conn = DriverManager.getConnection(“jdbc:postgresql://raven.acadiau.ca/ </li></ul><ul><li>2513DB”, “storexx_uid”, “storexx_pwd”); </li></ul><ul><li>Creates an object for issuing SQL statements (commands) to the connection: </li></ul><ul><li>pstmt = conn.prepareStatement(&quot;SELECT category_id,category_name, description,image FROM category WHERE parent = ?&quot;); </li></ul><ul><li>Two JDBC statement methods: </li></ul><ul><ul><li>executeQuery() – used for issuing SELECT queries </li></ul></ul><ul><ul><li>executeUpdate() – used for issuing DB inserts, updates and deletes </li></ul></ul>(The following examples are taken from IndexServlet.java)
  28. 28. JDBC Facilitates DB I/O <ul><li>The executeQuery() method returns a ResultSet object that contains the results of the query operation on the DB: </li></ul><ul><li>conn = StoreDatabase.getConnection(); </li></ul><ul><li>pstmt = conn.prepareStatement(&quot;SELECT category_id,category_name, </li></ul><ul><li>description, image FROM category WHERE parent = ?&quot;); </li></ul><ul><li>pstmt.setInt(1,getId()); </li></ul><ul><li>rs = pstmt.executeQuery(); </li></ul><ul><li>This “rs” object can be explored row by row: </li></ul><ul><li>while (rs.next()) { </li></ul><ul><li>int childId = rs.getInt(&quot;category_id&quot;); </li></ul><ul><li>String childName = rs.getString(&quot;category_name&quot;); </li></ul><ul><li>String childDesc = rs.getString(&quot;description&quot;); </li></ul><ul><li>String childImage = rs.getString(&quot;image&quot;); </li></ul><ul><li>… </li></ul><ul><li>} </li></ul>(The following examples are taken from IndexServlet.java)
  29. 29. JDBC Facilitates DB I/O <ul><li>DETAILS of getChildren: </li></ul><ul><li>List children = new Vector(); </li></ul><ul><li>Connection conn = null; </li></ul><ul><li>PreparedStatement pstmt = null; </li></ul><ul><li>ResultSet rs = null; </li></ul><ul><li>try { </li></ul><ul><li>conn = StoreDatabase.getConnection(); </li></ul><ul><li>pstmt = conn.prepareStatement(&quot;SELECT category_id,category_name,description,image FROM category WHERE parent = ?&quot;); </li></ul><ul><li>pstmt.setInt(1,getId()); </li></ul><ul><li>rs = pstmt.executeQuery(); </li></ul><ul><li>while (rs.next()) { </li></ul><ul><li>int childId = rs.getInt(&quot;category_id&quot;); </li></ul><ul><li>String childName = rs.getString(&quot;category_name&quot;); </li></ul><ul><li>String childDesc = rs.getString(&quot;description&quot;); </li></ul><ul><li>String childImage = rs.getString(&quot;image&quot;); </li></ul><ul><li>Category child = new Category(childId,childName,childDesc,childImage,this); </li></ul><ul><li>children.add(child); </li></ul><ul><li>child.isNew = false; </li></ul><ul><li>} </li></ul><ul><li>… </li></ul><ul><li>return children; </li></ul>
  30. 30. JSPs simplify JDBC (WS/DB2) <ul><li>Java Server Pages can make use of pre-written code to facilitate DB access </li></ul><ul><li>To connect: </li></ul><ul><ul><ul><li><jsp:dbconnect id=&quot;conn&quot; url=&quot;jdbc:db2:demomall&quot; </li></ul></ul></ul><ul><ul><ul><li>driver=&quot;COM.ibm.db2.jdbc.app.DB2Driver&quot; </li></ul></ul></ul><ul><ul><ul><li> userid=&quot;db2user&quot; passwd=&quot;db2pass&quot;> </li></ul></ul></ul><ul><ul><ul><li></jsp:dbconnect> </li></ul></ul></ul><ul><li>To execute a query: </li></ul><ul><ul><ul><li><jsp:dbquery connection=&quot;conn&quot; id=&quot;catalog&quot;> </li></ul></ul></ul><ul><ul><ul><li>SELECT … </li></ul></ul></ul><ul><ul><ul><li></jsp:dbquery> </li></ul></ul></ul><ul><li>To get the result (in this case a category name): </li></ul><ul><ul><ul><li><jsp:getProperty name=&quot;catalog&quot; property=“name&quot; /> </li></ul></ul></ul>
  31. 31. JSPs simplify JDBC <ul><li>Portion of code within index.jsp that accesses the Mall DB when displaying the categories at the top of the page: </li></ul><ul><li><a class=&quot;catLink&quot; </li></ul><ul><li>href=&quot;category.jsp?id=<jsp:getProperty name=&quot;category&quot; property=&quot;id&quot; />&quot; </li></ul><ul><li>onMouseOver=&quot;hiliteCell(<%=i%>)“ </li></ul><ul><li>onMouseOut=&quot;unhiliteCell(<%=i%>)&quot;> </li></ul><ul><li><jsp:getProperty name=&quot;category&quot; property=&quot;name&quot; /> </li></ul><ul><li></a> </li></ul>
  32. 32. JSPs simplify JDBC <ul><li>DETAILS: </li></ul><ul><li><% </li></ul><ul><li>int spaceWidth = 600 - (categories.size() * 110); </li></ul><ul><li>int i = 0; </li></ul><ul><li>for (Iterator it = categories.iterator(); it.hasNext();) { </li></ul><ul><li>Category c = (Category) it.next(); </li></ul><ul><li>pageContext.setAttribute(&quot;category&quot;,c); </li></ul><ul><li>%> </li></ul><ul><li><td width=&quot;110&quot;><table border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; width=&quot;110&quot;><tr><td align=&quot;center&quot;><font face=&quot;Verdana, Arial, Helvetica, sans-serif&quot; size=&quot;2&quot;> </li></ul><ul><li><a class=&quot;catLink&quot; </li></ul><ul><li>href=&quot;category.jsp?id=<jsp:getProperty name=&quot;category&quot; property=&quot;id&quot; />&quot; onMouseOver=&quot;hiliteCell(<%=i%>)&quot; onMouseOut=&quot;unhiliteCell(<%=i%>)&quot;><jsp:getProperty name=&quot;category&quot; property=&quot;name&quot; /></a> </li></ul><ul><li></font></td></tr></table></td> </li></ul><ul><li><% </li></ul><ul><li>i++; </li></ul><ul><li>} </li></ul><ul><li>%> </li></ul>
  33. 33. The Role of Database in E-Commerce <ul><li>Database is used within E-Commerce to provide dynamic ad hoc information on-demand to users </li></ul><ul><li>Store administrators use databases to set up categories and products in a secure and reliable manner </li></ul><ul><li>E-Commerce applications can be written with only the logical structure of data and not its physical storage </li></ul><ul><li>The database holds the content of a page and it also can hold the presentation of that content such that the same data can be presented in different ways to different customers </li></ul>
  34. 34. Major Architectural Components of the Web Internet Browser Database Server Client 1 Server A Server B Bank Server URL HTTP TCP/IP Browser Client 2 HTTP Server App. Server index.html Bank Server Dedicated prog.class
  35. 35. THE END [email_address]
  36. 36. SQL and WebSphere <ul><li>From index.jsp, the following gets the various category names (cgname) and reference numbers for a specified merchant (cgmenbr): </li></ul><ul><li>SELECT cgryrel.crccgnbr, category.cgname, category.cgrfnbr </li></ul><ul><li>FROM cgryrel, category </li></ul><ul><li>WHERE crmenbr = <%= request.getParameter(&quot;cgmenbr&quot;) %> AND </li></ul><ul><li> (cgryrel.crpcgnbr IS NULL) AND </li></ul><ul><li> category.cgmenbr = <%= request.getParameter(&quot;cgmenbr&quot;) %> AND </li></ul><ul><li> category.cgrfnbr = crccgnbr </li></ul>
  37. 37. SQL and WebSphere <ul><li>From index.jsp, the following gets the various category names (cgname) and reference numbers for a specified merchant (cgmenbr): </li></ul><ul><li>SELECT cgryrel.crccgnbr, category.cgname, category.cgrfnbr </li></ul><ul><li>FROM cgryrel, category </li></ul><ul><li>WHERE crmenbr = <%= request.getParameter(&quot;cgmenbr&quot;) %> AND </li></ul><ul><li> (cgryrel.crpcgnbr IS NULL) AND </li></ul><ul><li> category.cgmenbr = <%= request.getParameter(&quot;cgmenbr&quot;) %> AND </li></ul><ul><li> category.cgrfnbr = crccgnbr </li></ul>
  38. 38. SQL and WebSphere <ul><li>From product.jsp, the following gets the various </li></ul><ul><li>product category names (cgname) for specified merchant (cgmenbr) and category reference number (cgrfnbr): </li></ul><ul><li>SELECT category.cgname </li></ul><ul><li>FROM category </li></ul><ul><li>WHERE cgmenbr = <%=request.getParameter(&quot;cgmenbr&quot;) %> AND </li></ul><ul><li> cgrfnbr = <%= request.getParameter(&quot;cgrfnbr&quot;) %> </li></ul>
  39. 39. SQL and WebSphere <ul><li>From productDisplay.jsp, the following gets various product values for display for specified merchant (prmenbr) and product number (prrfnbr): </li></ul><ul><li>SELECT product.prsdesc, product.prnbr, product.prfull, product.prthmb,prodprcs.ppprc, prodprcs.ppcur, product.prldesc1,product.prldesc2, product.prldesc3, product.prwght, product.prwmeas, </li></ul><ul><li>product.prheight,product.prlngth, product.prwidth, product.prsmeas </li></ul><ul><li>FROM product, prodprcs </li></ul><ul><li>WHERE ppprnbr = prrfnbr AND </li></ul><ul><li> prmenbr = <%= request.getParameter(&quot;prmenbr&quot;) %> AND </li></ul><ul><li> prrfnbr = <%= request.getParameter(&quot;prrfnbr&quot;) %> </li></ul>
  40. 40. JDBC Facilitates WS DB I/O <ul><li>Connect to DB and establish a session: </li></ul><ul><ul><li>Connection myConnection = DriverManager.getConnection(&quot;jdbc:db2:demomall&quot;, &quot;db2user&quot;, &quot;db2pass&quot;); </li></ul></ul><ul><li>Create an object for issuing SQL statements (commands): </li></ul><ul><ul><li>Statement statement = myConnection.createStatement(); </li></ul></ul><ul><li>Two JDBC statement methods: </li></ul><ul><ul><li>executeQuery() – used for issuing SELECT queries </li></ul></ul><ul><ul><li>executeUpdate() – used for issuing DB inserts, updates and deletes </li></ul></ul>(The following examples are taken from IndexServlet.java)
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×