JSQL taglib ver. 1.1

    Custom JSP tags. Lets you connect through JDBC to any database, perform some SQL select operator and present output in JSON format. So the idea is very simple. JSP files with this taglib will present your data from DB in JSON format (it is your DAO layer). You can request these files via Ajax in any JavaScript framework (or even via plain JavaScript code). And the returned JSON lets you process SQL requests right in your JavaScript code. For example:
 


<%@ taglib uri="taglib.tld" prefix="get" %>

<get:JSQL driver="your_jdbc_driver" url="your_db_url" user="scott" password="tiger">
  <get:setQuery>select A,B from Table</get:setQuery>
</get:JSQL>

Tag executes the given query and outputs (inserts into page) result in JSOS format. JSOS data will be presented as an array of rows where the each row is a set of attributes:
 


[
{"attribute_name1:value1, attribute_name2:value2, ...},
{"attribute_name1:value1, attribute_name2:value2, ...},
...
]

so for the above mentioned example (select A,B from Table) it will be some like this:
 


[
{"A":"1","B":"2"},
{"A":"3","B":"4"},
...
]

Any null value will be presented as an empty string.

Tags are:

JSQL

Body tag presents data from your SQL datastore in JSON format. Parameters are:

1) driver JDBC driver
2) url database url
3) jndiname JNDI name for datasource (you must set this parameter or <driver,url> pair)
4) user Optional parameter: user name for database connection
5) password Optional parameter: password for database connection
6) callback Optional parameter: describes a name for JavaScript callback function

setQuery

Tag's body defines a SQL select operator. As for JDBC you may use ? sign as a mark for parameters. You can set actual values for parameters through setParameter tag.

setParameter

Tag's body defines one parameter for SQL statement. Parameters are:

1) position Optional parameter. Describes an index (the first parameter is 1, the second is 2 etc.) Default value is 1.
2) type Optional parameter. Describes a type for this parameter. Possible values are: boolean, byte, date, double, float, int, long, null, string, time, timestamp. Default value is string.

for downloading:

Library: jsqltag.jar    Description: taglib.tld

 © Coldbeans      Comments?

 See also Coldtags suite - the largest collection of custom JSP tags.

Also in Coldtags: