|
![]() |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--sunlabs.brazil.template.Template | +--sunlabs.brazil.sql.SqlTemplate
Sample Template class for running SQL queries via jdbc and placing the results into the request properties for further processing.
Foreach session, a connection is made to an sql database via jdbc. Session reconnection is attempted if the server connection breaks. An SQL query is issued, with the results populating the request properties. The following server properties are used:
prefix.driver=org.gjt.mm.mysql.Driver
).
prefix.url=jdbc:mysql://host/db?user=xxx&password=yyy
).
prefix.sqlPrefix=params params.user=my_name params.password=xxxAll of the parameters are supplied to the jdbc connection at connection time.
driver
and url
parameters are required.
All of the code between <sql>...</sql>
is taken to be an SQL query, and sent to the appropriate database
for execution. The result of the query is placed into the request
properties for use by other templates, such as the
BSLTemplate
or
PropsTemplate
.
For a discussion of how the results map to properties,
see below
.
Field Summary |
Fields inherited from class sunlabs.brazil.template.Template |
debug |
Constructor Summary | |
SqlTemplate()
|
Method Summary | |
boolean |
init(RewriteContext hr)
Called before this template processes any tags. |
Connection |
setupSql(String url,
Properties props)
Setup a connection to an SQL server. |
void |
tag_slash_sql(RewriteContext hr)
|
void |
tag_sql(RewriteContext hr)
Replace the SQL query with the appropriate request properties. |
Methods inherited from class sunlabs.brazil.template.Template |
done |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public SqlTemplate()
Method Detail |
public boolean init(RewriteContext hr)
Template
init
in interface TemplateInterface
init
in class Template
public void tag_sql(RewriteContext hr)
getProperty
).
${prefix}.${table_name}.${columname}.${key}
. If
the index
parameter is set, the key is the value of
the first column returned. Otherwise the key is the row number,
and the additional property ${prefix}.rows
contains a
list of all the row numbers returned.
public void tag_slash_sql(RewriteContext hr)
public Connection setupSql(String url, Properties props)
|
Version 2.1, Generated 12/30/04 Copyright (c) 2001-2004, Sun Microsystems. |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |