Use the <tsx:dbmodify> syntax to establish a connection to a database and then add records to a database table.
The <tsx:dbmodify> tag:
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>
This 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:
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>