Label Summary Tag Reference Example Javadocs Revised Record Developer Note
Overview
DBTAGS Custom Label Library is used to read and write SQL databases.
Requirement
JSP requirements This requires a servlet engine that supports the JSP specification 1.2 version. Although it can also work in a JSP version 1.1 engine such as Tomcat, it is not possible to work on the engine such as WebLogic. It is designed according to JSP 1.2 specification, it needs tag:
JSP: SetProperty and JSP: The value of the Name attribute in getProperty is an object obtained by the FindAttribute () method of the PageContext object.
The JSP 1.1 specification does not require this behavior and Tomcat happens to support and WebLogic does not support. There is also a fairly straightforward method to write a custom label for WebLogic users. There is already ready-made examples available here. The DBTags requires the DBTags library supports data sources, which is not part of the Java 2 Standard Edition. In order to use the database, use J2EE, or download the JDBC 2.0 Optional API.
Configure
Use the following steps to make your web application use this tag library:
Copy Label Library Description Document DBTags.TLD to your Web application / web-inf subdirectory to copy the label library JAR file to the application / web-inf / lib sub-directory. Add below /Web-inf/web.xml ::
Use this tag library in your JSP page, plus the following on top of each page:
<% @Tab Uri = "http://jakarta.apache.org/taglibs/dbtags" prefix = "sql"%>
"SQL" is the label prefix you want to use, you can change it to your favorite value.
Documentation
Simple Usage Example The following is a JSP page source file in a print name in a print table: <% @Tab Uri = "http://jakarta.apache.org/taglibs/dbtags" prefix = "sql"%>
<% - open a database connection -%>
JDBC: MySQL: // localhost / test sql: URL>
Org.gjt.mm.mysql.driver sql: driver>
SQL: Connection>
<% - Open a Database Query -%>
SELECT ID, NAME, Description from test_booksorder by 1
SQL: Query>
<% - loop through the rows of your query -%>
td>
td>
[No Description] SQL: WASNULL> TD>
TR>
sql: resultset>
SQL: Statement>
table>
<% - Close a Database Connection -%>
Tag Details The following is the overall description of the DBTags tag library, some details of the label, such as all possible properties of the Connection, Statement, ResultSet, and PreparedStatement tags, not discussed here. Tag Reference lists all details. The Connection tag opens a connection with three ways to open a database connection: 1. Using the Database URL Connection tab You can accept a database URL to get a connection: <% - open a database connection -%>
<% - reguired -%>
JDBC: MySQL: // localhost / test sql: URL>
<% - Optional -%>
Org.gjt.mm.mysql.driver sql: driver>
<% - Optional -%>
root sql: userid>
<% - Optional -%>
NOTVERYSECURE SQL: Password>
SQL: Connection> "ID" attribute is required. After ending the label, a java.sql.connection object is added to a PageContext property, which can be used by other labels including statement, preparedstate, and CloseConnection. Do not contain database URLs, drive names, user ID, or passwords in the label, you can use optional properties "initparameter": <% - store your connection info in Web.xml file -%>
SQL: Connection> 2. Using the data source Connection can also accept a reference to the javax.sql.dataSource object to the servlet property. (This attribute is obtained by the FindAttribute () method of PageContext.): <% - Open a Database Connection -%>
<% - Optional -%>
root sql: userid>
<% - Optional -%>
NOTVERYSECURE SQL: Password>
SQL: Connection> 3. JDBC Data Source using JNDI can also accept a JDBC data source named using JNDI. <% - open a database connection -%>
Close connection to pass a Connection's reference to the "CloseConnection" tab Close a connection: <% - unless you use your own connection The pool, otherwise always turn off the connection -%>
Statement Tag "Statements" is a way to submit a query to the database. (The other is to use "preparedStatement".) Syntax based on Statement query is unfamiliar with anyone who knows SQL. In order to query the database, open a "Statement" tab, pass it to a SQL "Query", then apply for INSERTS, UPDATES, and DELETES "Execute", or call the ResultSet tab to cycle on the result of a SELECT declaration. Here is a simple INSERT: <% - inserting a line into the database -%>
SQL: Statement> Essential SQL "EscapeSQL" tab With the possible single quotes in the value input in a SQL query. Error handling the default, the execution of the SQL query (such as primary key ViOLATIONS, the incomplete SQL declaration) will result in the failure of the JSP page, you can selectively set the "IgnoreErRors" property of the "Execute" tab "True", which will make SQL errors to standard output without terminating pages: <% - this SQL query is an incomplete-%>
Delete * from test_books sql: query>
<% - query will fail, but the page will continue -%>
SQL: Statement> Blank Processing All Statement and PreparedStatement automatically removes blank. The PreparedStatement label "prepared statements" is a relatively advanced form of the SQL query. It is not directly inserted into the SQL declaration, but it is necessary to set a '' 'symbol in the need to set it, and then use a set of independent labels to actually set those values. Below is a prepaaredStateMent version of the example used in Statement: <% - insert a line to the database -%>
<% - Set the SQL query. Note "Name" value lack quotation marks -%>
sql: preparedStatement> A advantage of prepared Statements is that you don't need to perform SQL escape on text. However, remembering the Standard Statements For those databases and the PREPARED Statements, the drive is better. SetColumn Tags You can place the setColumn tab of Prepared Statements in front of the Execute or ResultSet tag, or the Execute tag. The Execute tag never outputs its content (Body), so placing the SetColumn tab can prevent unnecessary blank. The ResultSet Tag Resultset is the result of a SELECT declaration. The ResultSet label is automatically looped, each line. Use the "getColumn" tab to extract the value from each row and then display them, or save them a string: <% - In an HTML form, print the line -%>
SELECT ID, NAME, Description from test_books
ORDER BY 1
SQL: Query>
<% - Row in the result of cyclic extraction inquiry -%>
td>
td>
<% - If the book is not explained, print a note -%>
[No Description] SQL: WASNULL> TD>
TR>
sql: resultset>
SQL: Statement>
Table> "WASNULL" and "WasNotnull" labels "WASNull" tab only the content in the body when you encounter a null value in a database in the previous "getColumn" tab. You can only use the "WASNull" tab when you have an RESULTSET and the "getColumn" tab has been executed. "WasNotnull" label does not generate an empty value (NULL) in its previous GetColumn tag to perform content in its body. See TAG Reference Examples. "GetColumn" tab The getColumn tag performs one of the two features. You can:
Directly to the JSP output column value (default behavior) <% - output value to JSP -%>
, or a value as a String object is written as a property, through the "to" attribute. If you like, you can also assign a value different from "Page" for the "Scope" property. If the value of this column in the database is NULL, the getColumn tag will not create properties. Below is an integer request attribute using a getColumn tag: <% - Note The attribute of the request will be a string -%> "getnumber" tab If you want to have more control over the digital format, use the GetNumber tab. The "format" property can be the mode acceptable by the DecimalFormat constructor or the following types: "currency", "percent" or "number". "Locale" attribute can have one to three parts, that is, the form of the local constructor acceptable: language, country, and variables. They use "_" segmentation. For example: <% - formatted database value is the UK currency form -%>
If the Format and Locale properties are not set, the output will be like getColumn. Time tags There are several tags that are designed to show time-related data: getTime, getTimeStamp, and getdate. The "Format" property can be in the form of SimpleDateFormat or a type: "full", "long", "medium" or "short". This attribute is optional. "Locale" attribute can have one to three parts, that is, the form of the local constructor acceptable: language, country, and variables. They use "_" segmentation. Prohibition of loop defaults RESULTSET tags are performed on the RESULTSET. This feature can be disabled by setting the optional attribute "LOOP" to "false" and then manually operates the ResultSet object or passes it to another custom label.
SQL: Statement> You can also use a RowSet object with a RowSet object with a RowSet object. By setting the option "name", the ResultSet label will look up a ResultSet object (including RowSets) and store it in page, request, or session context. By setting the optional properties "Scope", you can specify the context to include your ResultSet / RowSet. Note When you read a ResultSet / Rowset from an attribute, the ResultSet tag may not be within the Statement tag. <% - Each row of RESULTSET / ROWSET, no matter where it comes -%>
td>
td>
<% - If the book is not explained, print a note -%>
[No Description] SQL: WASNULL> TD>
TR>
SQL: ResultSet> "Wasempty" and "WasNotempty" tab "WASEMPTY" tab only the contents of its body when the last ResultSet label is obtained from 0 rows from the database. It must be placed in a resultset tag, otherwise it will be wrong. "WasNotempty" tab gets more than 0 rows from the database in the database. See TAG Reference Acquisition Examples. "RowCount" tab "RowCount" tab prints the number of rows returned by the database. It can be used in the ResultSet tag to provide a run count, or the total number of prints is used after the ResultSet tag. See TAG Reference Acquisition Examples. Using this tag before ResultSet will generate an error.
TAG summary
Connection tag
Get a java.sql.connection object from DRIVERMANAGER or DATASOURCE. The URL sets the database URL in the closed Connection tag. JNDINAME Sets JDBC data sources named JNDI in a closed Connection tag. Driver sets the drive class name in the closed Connection tag. UserID Sets the username of the Connection tag. Password Sets the username password for the Connection tag. CloseConnection closes the specified connection. The "conn" property is a Connection object on the context of the page.
Single STATEMENT label
Statement creates and executes a database query. Escapesql replaces each single quotation in the label to a pair of single quotes.
Statement / prepaaredStatement label
Query sets a query for a Statement or PreparedStatement tag. Execute executes an insert, update or delete for the Statement or PreparedStateMent tag.
Single prepaaredStatement label
PreparedStatement creates and executes a marker database query. SetColumn Sets a field in the PreparedStatement. Set the value to a string in the label.
Resultset label
The ResultSet Tag Resulset executes the query and loops to perform the result in the closed Statement or the PreparedStatement tab. The content of this label is executed on the RESULTSET. Optional Properties "LOOP" Specifies whether the label is executed on each line, or simply simply assigning the ResultSet to the page specified by "ID". WASNULL performs label when getting a NULL value from the database from the database. You must have a getColumn tag in a RESULTSET tag, otherwise an error will be generated. WasNotnull If the last getColumn label is not a NULL value to execute a label from a NULL value from the database. GetColumn gets a field value in a closed resultset as a string. Field Index With the "Position" property setting, use the "to" property to set this value to a serlvet property rather than a label. The range of servlet properties uses the "Scope" property (default Page). GetNumber and getColumn are similar, but provide more accurate control over digital format. The "format" property can be in the form of the DecimalFormat constructor or a type: "currency", "percent" or "number". "Locale" attribute can have one to three parts, that is, the form of the local constructor acceptable: language, country, and variables. They use "_" segmentation. If the Format and Locale properties are not set, the output will be the same as getColumn. GetTime and getColumn are similar, but provide more accurate control over java.sql.time format. The "Format" property can be in the form of SimpleDateFormat or a type: "full", "long", "medium" or "short". This attribute is optional. "Locale" attribute can have one to three parts, that is, the form of the local constructor acceptable: language, country, and variables. They use "_" segmentation. If the Format and Locale properties are not set, the output will be the same as getColumn. GetTimeStamp and getColumn are similar, but provide more accurate control over java.sql.timestamp format. The "Format" property can be in the form of SimpleDateFormat or a type: "full", "long", "medium" or "short". This attribute is optional. "Locale" attribute can have one to three parts, that is, the form of the local constructor acceptable: language, country, and variables. They use "_" segmentation. If the Format and Locale properties are not set, the output will be the same as getColumn. GetDate and getColumn are similar, but provide more accurate control over java.sql.date format. The "Format" property can be in the form of SimpleDateFormat or a type: "full", "long", "medium" or "short". This attribute is optional. "Locale" attribute can have one to three parts, that is, the form of the local constructor acceptable: language, country, and variables. They use "_" segmentation.
WaSempty Label Get 0 lines from the database to perform labels from the database. You must use otherwise an error after the RESULTSET tag. WasNotempty's last RESULTSET label gets more than 0 lines to perform labels from the database. You must use otherwise an error after the RESULTSET tag. RowCount "RowCount" tab prints the number of rows returned by the database. It can be used in the ResultSet tag to provide a run count, or the total number of prints is used after the ResultSet tag. Using this tag before ResultSet will generate an error. TAG reference
connection Availability:.. 1.0 Get a java.sql.Connection object from the DriverManager or a DataSource Tag BodyJSP Restrictions None AttributesNameRequired Runtime Expression Evaluation Availability id yes no 1.0 Name of the resulting Connection attribute dataSource no no 1.0 Name of an existing page attribute that contains a DataSource object. jndiName no no 1.0 Name used to find a datasource via jndi. VariablesNameScopeAvailability id attribute value End of tag to end of page 1.0 PropertiesNameGetSetAvailability catalog yes yes 1.0 Set the catalog for this connection. closed yes no 1.0 False if the connection Is Open, True if it is not. Readonly Yes Yes 1.0 True if The connection has read-only permission. Examples method 1: Using The DriverManager
<% - open a database connection -%>
<% - reguired -%>
JDBC: MySQL: // localhost / test sql: URL>
<% - Optional -%>
Org.gjt.mm.mysql.driver sql: driver>
<% - Optional -%>
root sql: userid>
<% - Optional -%>
NOTVERYSECURE SQL: Password>
SQL: Connection>
Method 2: using a datasource
<% - open a database connection -%>
<% - Optional -%>
root sql: userid>
<% - Optional -%>
NOTVERYSECURE SQL: Password> SQL: Connection>
Method 3: using a jndi named DataSource
<% - open a database connection -%>
url Availability:. 1.0 Sets the database URL of the enclosing connection tag Tag BodyJSP RestrictionsUse inside a connection tag.AttributesNameRequired Runtime Expression Evaluation Availability initParameter no no 1.0 Optional attribute, indicating the name of an init parameter VariablesNoneExamples
<% - EXAMPLE 1: USING TAG BODY -%>
JDBC: MySQL: // localhost / test sql: URL>
SQL: Connection>
<% - EXAMPLE 2: Using An Init Parameter -%>
SQL: Connection>
jndiName Availability:. 1.0 Sets the JNDI named JDBC DataSource of the enclosing connection tag Tag BodyJSP RestrictionsUse inside a connection tag.AttributesNameRequired Runtime Expression Evaluation Availability initParameter no no 1.0 Optional attribute, indicating the name of an init parameter VariablesNoneExamples
<% - EXAMPLE 1: USING TAG BODY -%>
Java: / Comp / JDBC / TEST SQL: JNDINAME>
SQL: Connection>
<% - EXAMPLE 2: Using An Init Parameter -%>
SQL: Connection>
.. Driver Availability: 1.0 Sets the driver class name for the connection tag Tag BodyJSP RestrictionsUse inside a connection tag.AttributesNameRequired Runtime Expression Evaluation Availability initParameter no no 1.0 Optional attribute, indicating the name of an init parameter VariablesNoneExamples <% - example 1: USING TAG BODY -%>
JDBC: MySQL: // localhost / test sql: URL>
Org.gjt.mm.mysql.driver sql: driver>
SQL: Connection>
<% - EXAMPLE 2: Using An Init Parameter -%>
SQL: Connection>
userId Availability:. 1.0 Sets the user id for the connection tag Tag BodyJSP RestrictionsUse inside a connection tag.AttributesNameRequired Runtime Expression Evaluation Availability initParameter no no 1.0 Optional attribute, indicating the name of an init parameter VariablesNoneExamples.
<% - EXAMPLE 1: USING TAG BODY -%>
JDBC: MySQL: // localhost / test sql: URL>
root sql: userid>
SQL: Connection>
<% - EXAMPLE 2: Using An Init Parameter -%>
SQL: Connection>
password Availability: 1.0 Sets the password for the connection tag Tag BodyJSP RestrictionsUse inside a connection tag.AttributesNameRequired Runtime Expression Evaluation Availability initParameter no no 1.0 Optional attribute, indicating the name of an init parameter VariablesNoneExamples <% - example 1:.. using the TAG Body -%>
JDBC: MySQL: // localhost / test sql: URL>
root sql: userid>
NOTVERYSECURE SQL: Password>
SQL: Connection>
<% - EXAMPLE 2: Using An Init Parameter -%>
SQL: Connection>
closeConnection Availability: 1.0 Close the specified connection The "conn" attribute is the name of a connection object in the page context Tag Bodyempty Restrictions None AttributesNameRequired Runtime Expression Evaluation Availability conn yes no 1.0 Id of the connection you want to close VariablesNoneExamples...
<% - open a database connection -%>
JDBC: MySQL: // localhost / test sql: URL>
root sql: userid>
NOTVERYSECURE SQL: Password>
SQL: Connection>
<% - Statement Tags Go Here -%>
statement Availability:. 1.0 Create and execute a database query Tag BodyJSP Restrictions None AttributesNameRequired Runtime Expression Evaluation Availability id yes no 1.0 Script variable id for use with standard jsp:. getProperty tag conn yes no 1.0 id of the connection to use VariablesNameScopeAvailability id attribute value Nested within tag 1.0 PropertiesNameGetSetAvailability fetchSize yes yes 1.0 the number of rows that should be fetched from the database when more rows are needed maxRows yes yes 1.0 the maximum number of rows that a ResultSet object can contain (handy!) queryTimeout yes yes 1.0 the number Of Seconds The Driver Will Wait for A Statement Object To Execute Examples <% - Insert A Row Into The Database -%>
Escapesql availability: 1.0 replaces each single quote in the Tag body with a pair of single quotes. Tag bodyjsp Restrictions INSIDE A Query Tag.attributesnoneVariablesnoneexamples
Query Availability: 1.0 set a query for a statement or preparedStatement Tag Tag Bodyjsp Restrictionsuse Inside a statement or preparedState Tag.attributesnonevariablesnoneexamples
execute Availability: 1.0 Executes an insert, update or delete for a statement or preparedStatement tag Tag BodyJSP RestrictionsUse inside a statement or preparedStatement tag.AttributesNoneVariablesNoneExamples
preparedStatement Availability: 1.0 Create and execute a tokenized database query Tag BodyJSP RestrictionsThe scipt variable is not available until after the query tag is called.AttributesNameRequired Runtime Expression Evaluation Availability id yes no 1.0 Script variable id conn yes no 1.0 id of the connection to use VariablesNameScopeAvailability id attribute value Nested within tag 1.0 PropertiesNameGetSetAvailability fetchSize yes yes 1.0 the number of rows that should be fetched from the database when more rows are needed maxRows yes yes 1.0 the maximum number of rows that a ResultSet object can contain (handy!) queryTimeout yes yes 1.0 The Number of Seconds The Driver Will Wait for A Statement Object To Execute Examples <% - Insert A Row Into The Database -%>
setColumn Availability:. 1.0 Set a field in a preparedStatement Set the value as a String inside the tag body Tag BodyJSP RestrictionsUse within the preparedStatement tagAttributesNameRequired Runtime Expression Evaluation Availability position yes no 1.0 Column position VariablesNoneExamples.
<% - use the tag body -%>
<% = SomeValue%> SQL: SETCOLUMN>
resultSet Availability: 1.0 JSP tag resulset, executes the query and loops through the results for the enclosing statement or preparedstatement tag The body of this tag is executed once per row in the resultset The optional "loop" attribute, which default to true,.. specifies whether to execute the tag body once per row "true", or to simply assign the ResultSet to the page attribute specified by "id". Tag BodyJSP RestrictionsIf a name attribute is not supplied, use within a statement or preparedStatement and after a query . If a name attribute is supplied, there are no restrictions.AttributesNameRequired Runtime Expression Evaluation Availability id yes no 1.0 Script variable id loop no no 1.0 True: execute the tag body once per row in the result set, automatically advancing the rows False.: Execute the tag body overce. Name no no 1.0 name of an attribute containing a resultset Object. if you pull a resultset Object from an attribute, it is not necessary to place this Tag i nside of a statement. scope no no 1.0 Scope (page, request, session, or application) to search for the ResultSet attribute indicated in the "name" attribute. If this is not supplied, we use the default findAttribute () behaviour. VariablesNameScopeAvailability id attribute value Nested within tag 1.0 PropertiesNameGetSetAvailability fetchSize yes yes 1.0 the number of rows that should be fetched from the database when more rows are needed Examples <% - open a database query -%>
SELECT ID, NAME, Description from test_books
ORDER BY 1
SQL: Query>
<% - loop through the rows of your query -%>
td>
td>
[No Description] SQL: WASNULL> TD>
TR>
sql: resultset>
SQL: Statement>
table>
wasNull Availability:. 1.0 Executes its body if the last getColumn tag received a null value from the database You must be inside a resultset tag and there must be a previous getColumn tag, or an error will be generated Tag BodyJSP RestrictionsMust be used following a. GetColumn tag.attributesnonevariablesnoneexamples
<% - Open a Database Query -%>
SELECT ID, NAME, Description from test_books
ORDER BY 1
SQL: Query>
<% - loop through the rows of your query -%>
td>
td>
[No Description] SQL: WASNULL> TD>
TR>
sql: resultset>
SQL: Statement>
wasNotNull Availability: 1.0 Executes its body if the last getColumn tag did not encounter a null value from the database Tag BodyJSP RestrictionsMust be used following a getColumn tag.AttributesNoneVariablesNoneExamples.
getColumn Availability: 1.0 Gets the value, as a String, of a coulmn in the enclosing resultset The column number is set via the "position" attribute You can optionally set the value, as a String, to a serlvet attribute instead of the.. tag body with the "to" attribute. The scope of the servlet attribute is specified by the "scope" XML attribute (default = page). Tag Bodyempty RestrictionsUse within the resultSet tagAttributesNameRequired Runtime Expression Evaluation Availability position no no 1.0 Column position colName no no 1.0 Column name to no no 1.0 Optionally assign the String to an attribute rather than the JSP output. scope no no 1.0 Optionally change the scope of the attribute designated in "to" (default = page). VariablesNoneExamples
<% - Output to the JSP Directly -%>
getNumber Availability: 1.0 Similar to getColumn, but provides more precise control over number formatting The "format" attribute can be either a pattern as accepted by the DecimalFormat constructor or a style:.. "CURRENCY", "PERCENT" or "NUMBER" The "locale" attribute can have one to three components as accepted by the locale constructor: language, country and variant They are separated by "_" If neither the format nor locale attribute is set, output should be identical to getColumn Tag Bodyempty... RestrictionsUse within the resultSet tagAttributesNameRequired Runtime Expression Evaluation Availability position no no 1.0 Column position colName no no 1.0 Column name to no no 1.0 Optionally assign the String to an attribute rather than the JSP output. scope no no 1.0 Optionally change the scope of the attribute designated IN "to" (default = page). Locale No Yes 1.0 Format According to a Particular Locale. Format No Yes 1.0 Specify A Format for the number. v Ariablesnoneexamples <% - Format A Database Value As English Currency -%>
getTime Availability: 1.0 Similar to getColumn, but provides more precise control over java.sql.Time formatting The "format" attribute can be either a pattern as accepted by SimpleDateFormat or a style:. "FULL", "LONG", "MEDIUM" . or "SHORT" The "locale" attribute can have one to three components as accepted by the locale constructor:. language, country and variant They are separated by "_" If neither the format nor locale attribute is set, output should be. identical to getColumn. Tag Bodyempty RestrictionsUse within the resultSet tagAttributesNameRequired Runtime Expression Evaluation Availability position no no 1.0 Column position colName no no 1.0 Column name to no no 1.0 Optionally assign the String to an attribute rather than the JSP output. scope no no 1.0 Optionally change The Scope of the Attribute Designated in "To" (default = page). Locale No Yes 1.0 Format According to a Particular Locale. Format No Yes 1.0 Specify A Format for the Time. Variables Noneexamples
getTimestamp Availability: 1.0 Similar to getColumn, but provides more precise control over java.sql.Timestamp formatting The "format" attribute can be either a pattern as accepted by SimpleDateFormat or a style:. "FULL", "LONG", "MEDIUM" . or "SHORT" The "locale" attribute can have one to three components as accepted by the locale constructor:. language, country and variant They are separated by "_" If neither the format nor locale attribute is set, output should be. identical to getColumn. Tag Bodyempty RestrictionsUse within the resultSet tagAttributesNameRequired Runtime Expression Evaluation Availability position no no 1.0 Column position colName no no 1.0 Column name to no no 1.0 Optionally assign the String to an attribute rather than the JSP output. scope no no 1.0 Optionally change The Scope of the Attribute Designated in "To" (Default = Page). Locale No Yes 1.0 Format According to a Particular Locale. Format No Yes 1.0 Specify A Format for the Timest amp. variablesnoneexamples
getDate Availability: 1.0 Similar to getColumn, but provides more precise control over java.sql.Date formatting The "format" attribute can be either a pattern as accepted by SimpleDateFormat or a style:. "FULL", "LONG", "MEDIUM" . or "SHORT" It is required The "locale" attribute can have one to three components as accepted by the locale constructor:... language, country and variant They are separated by "_" Tag Bodyempty RestrictionsUse within the resultSet tagAttributesNameRequired Runtime Expression Evaluation Availability position no no 1.0 Column position colName no no 1.0 Column name to no no 1.0 Optionally assign the String to an attribute rather than the JSP output. scope no no 1.0 Optionally change the scope of the attribute designated in "to" (default = Page). Locale No Yes 1.0 Format According to a Particular Locale. Format No Yes 1.0 Specify A Format for the date. variablesnoneexamples
wasEmpty Availability: 1.0 Executes its body if the last ResultSet tag received 0 rows from the database You must be after a ResultSet tag, or an error will be generated Tag BodyJSP RestrictionsUse after a ResultSet tag.AttributesNoneVariablesNoneExamples..
<% - shwing the contents of the table -%>
ID TH>
Name TH>
Description TH> TR>
SELECT ID, NAME, Description from test_books
SQL: Query>
td>
td>
td>
TR>
sql: resultset>
<% - Show Different Text, Depending On Whather OR Not NOT
Any Rows WERE RETRIEVED -%>
NO ROWS RETRIEVED. SQL: WASEMPTY>
Rows Retrieved. SQL: WASNOTEMPTY>
td>
TR>
SQL: PreparedStatement>
wasNotEmpty Availability: 1.0 Executes its body if the last ResultSet tag received more than 0 rows from the database You must be after a ResultSet tag, or an error will be generated Tag BodyJSP RestrictionsUse after a ResultSet tag.AttributesNoneVariablesNoneExamples..
<% - shwing the contents of the table -%>
ID TH>
Name TH>
Description TH> TR>
SELECT ID, NAME, Description from test_books
SQL: Query>
td>
td>
td>
TR>
sql: resultset>
<% - Show Different Text, Depending On Whather OR Not NOT
Any Rows WERE RETRIEVED -%>
NO ROWS RETRIEVED. SQL: WASEMPTY> Rows Retrieved. SQL: WASNOTEMPTY>
td>
TR>
SQL: PreparedStatement>
rowCount Availability:.. 1.0 Prints out the number of rows retrieved from the database It can be used inside a ResultSet tag to provide a running count of rows retreived, or after the ResultSet tag to display the total number Using the tag before the ResultSet will Product an error. Tag bodyempty restrictionsuses inside or after a resultset tag (not before) .attributesnonevariablesnoneexamples
<% - shwing the contents of the table -%>
ID TH>
Name TH>
Description TH> TR>
SELECT ID, NAME, Description from test_books
SQL: Query>
td>
td>
td>
TR>
sql: resultset>
<% - Show Different Text, Depending On Whather OR Not NOT
Any Rows WERE RETRIEVED -%>
NO ROWS RETRIEVED. SQL: WASEMPTY>
Rows Retrieved. SQL: WASNOTEMPTY>
td>
TR>
SQL: PreparedStatement>
Examples
See Custom Tag Library.
Java Docsjava Programmers Can View The Java Class Documentation for this Tag Library as javadocs.
Revision History
Review The Complete Revision History of this Tag Library.
Developers' Notes
Last Updated: 08/14/2001
On The Radar Screen
Here's a list of what's cooking with dbtags. If ''VE MADE A SUGGESTION OR CONTRIBUTED A PATCH That You Think We've Missed, Send a Note To Taglibs-user@jakarta.apache.org.
TO-DO:
Add support for rowsets. [Update: Preliminary Support Has Been Added, See the History for Details]
Under considration:
ResultSet / Rowset "Paging".
On The Back Burner:
Connection Management. There Has Been Some Discussion Lately on If / How To Terminate Connections Upon a JSP Page Error WITHOUT MAKING The usage Too Cluny. I Think Waiting for That Spark of Inspiration.