<tsx:dbmodify>
Use the <tsx:dbmodify> syntax to establish a connection to a database and then add records to a database table.
The <tsx:dbmodify> tag:
- Refers to a <tsx:dbconnect> in the same JSP file and uses the information provided by that database connection to determine the database URL and driver. The user ID and password are also obtained from the <tsx:dbconnect> if those values are provided in the <tsx:dbconnect>.
- Establishes a new connection.
- Updates a table in the database.
- Closes the connection (releases the connection resource).
The <tsx:dbmodify> syntax is:
<tsx:dbmodify connection="connection_id" > <!-- Any valid database update commands can be -> <!-- placed within the tsx:dbmodify tag. Any other -> <!-- syntax, including HTML comments, are not valid. -> </tsx:dbmodify>The following list describes the attributes and their values:
connection
The identifier of a <tsx:dbconnect> in this JSP file. That <tsx:dbconnect> provides the database URL, driver name, and (optionally) the user ID and password for the connection.Database commands
For more information about database commands, see this resource:
- DB2 Universal Database for iSeries SQL Reference (V5R1)
- DB2 Universal Database for iSeries SQL Reference (V5R2)
In the following example, a new employee record is added to a database. The values of the fields are based on user input from this JSP and referenced in the database commands using the <tsx:getProperty> tag.
<% String empno = request.getParameter("EMPNO"); %> <% String firstnme = request.getParameter("FIRSTNME"); %> <% String midinit = request.getParameter("MIDINIT"); %> <% String lastname = request.getParameter("LASTNAME"); %> <% String workdept = request.getParameter("WORKDEPT"); %> <% String edlevel = request.getParameter("EDLEVEL"); %> <tsx:dbmodify connection="conn" > INSERT INTO WSDEMO.EMPLOYEE (EMPNO,FIRSTNME,MIDINIT,LASTNAME,WORKDEPT,EDLEVEL) VALUES ( '<%=empno%>', '<%=firstnme%>', '<%=midinit%>', '<%=lastname%>', '<%=workdept%>', <%=edlevel%> ) </tsx:dbmodify>