SQL Query

ID Name Address 1 Address 2 City State Zip Code Credit Limit Discount Code
1 Jumbo Eagle Corp 111 E. Las Olivas Blvd Suite 51 Fort Lauderdale FL 95117 100000 N
2 New Enterprises 9754 Main Street P.O. Box 567 Miami FL 95035 50000 M
25 Wren Computers 8989 Red Albatross Drive Suite 9897 Houston TX 85638 25000 M
3 Small Bill Company 8585 South Upper Murray Drive P.O. Box 456 Alanta GA 12347 90000 L
36 Bob Hosting Corp. 65653 Lake Road Suite 2323 San Mateo CA 94401 65000 H
106 Early CentralComp 829 E Flex Drive Suite 853 San Jose CA 95035 26500 L
149 John Valley Computers 4381 Kelly Valley Ave Suite 77 Santa Clara CA 95117 70000 L
863 Big Network Systems 456 444th Street Suite 45 Redwood City CA 94401 25000 N
777 West Valley Inc. 88 Northsouth Drive Building C Dearborn MI 48128 100000 L
753 Zed Motor Co 2267 NE Michigan Ave Building 21 Dearborn MI 48128 5000000 H
722 Big Car Parts 52963 Notouter Dr Suite 35 Detroit MI 48124 50000 N
409 Old Media Productions 4400 527th Street Suite 562 New York NY 10095 10000 L
410 Yankee Computer Repair Ltd 9653 211th Ave Floor 4 New York NY 10096 25000 M
Show All Records

This example demonstrates an inline SQL Query being used to render a table.

An JSONObject is created to pull data from page parameters with blank string defaults for the case where a parameter was not passed. The JSONObject is then bound to the query, overriding the default of pulling values from the JSP scopes. (i.e. page, request, session, application)

Values are encoded using the ${virge:html(value)} function to prevent HTML injection.

<%@taglib uri="convirgance:web" prefix="virge" %> <virge:object var="binding"> <virge:key name="zipcode" value="${param.zipcode}" default="" /> <virge:key name="state" value="${param.state}" default="" /> <virge:key name="discountCode" value="${param.discountCode}" default="" /> </virge:object> <virge:query var="customers" jndi="jdbc/sample" binding="${binding}"> select * from APP.CUSTOMER where (:zipcode = '' or ZIP = :zipcode) and (:state = '' or STATE = :state) and (:discountCode = '' or DISCOUNT_CODE = :discountCode) <//virge:query> <virge:iterate var="customer" items="${customers}"> <tr> <td>${virge:html(customer.CUSTOMER_ID)}</td> <td>${virge:html(customer.NAME)}</td> <td>${virge:html(customer.ADDRESSLINE1)}</td> <td>${virge:html(customer.ADDRESSLINE2)}</td> <td>${virge:html(customer.CITY)}</td> <td><a href="?state=${virge:html(customer.STATE)}">${virge:html(customer.STATE)}</a></td> <td><a href="?zipcode=${virge:html(customer.ZIP)}">${virge:html(customer.ZIP)}</a></td> <td>${virge:html(customer.CREDIT_LIMIT)}</td> <td><a href="?discountCode=${virge:html(customer.DISCOUNT_CODE)}">${virge:html(customer.DISCOUNT_CODE)}</a></td> </tr> </virge:iterate>