<%@ taglib uri="http://jakarta.apache.org/taglibs/dbtags" prefix="sql" %>
Opening connection
<%=request.getParameter("dburl")%>
<%=request.getParameter("driver")%>
Connection is closed?
Deleteing the results of the last test
delete from test_books where id > 2
Showing current contents of the "test_books" table
id | name | description | rowCount |
select id, name, description from test_books
order by 1
|
|
[no description] |
|
No rows retrieved.
rows retrieved.
|
Inseting a row using the "statement" tag
<%-- added try block because InstantDB has trouble with SQL escaping --%>
<% try { %>
insert into test_books (id, name)
values (3, 'Gravity's Rainbow')
<% } catch (javax.servlet.jsp.JspTagException e) { %>
Possible SQL error:
- <%= e.toString() %>
Your database (InstantDB?) may not support
standard SQL escaping. You will probably have to escape your
SQL manually, rather than use the <sql:escapeSql> tags.
<% } %>
Showing current contents of the "test_books" table
id | name | description |
select id, name, description from test_books
order by 1
|
|
[no description] |
No rows retrieved.
rows retrieved.
|
Select all book titles like "%ra%"
id | name | description |
select id, name, description from test_books
where name like '%ra%'
|
|
[no description] |
No rows retrieved.
rows retrieved.
|
Selecting back the title of book 3, assigning the value to an attribute
select name from test_books
where id = 3
order by 1
retrieved row
No rows retrieved.
rows retrieved.
Inserting that title into a new row with a "preparedStatement" tag, adding
a description
insert into test_books (id, name, description)
values (?, ?, ?)
The contents of an execute body are not included in the output
4
<%=pageContext.getAttribute("bookName")%>
book by Pynchon
Nested Query example: Reselecting every row in the table
id | name | description |
select id, name, description from test_books
order by 1
|
|
Description: <%= pageContext.getAttribute("description") %>
[no description] |
<% int colId = rset4.getInt(1); %>
select id, name, description from test_books
where id = <%= colId %>
|
|
Description: <%= pageContext.getAttribute("description") %>
[no description] |
No rows retrieved.
rows retrieved.
|
For fun, pretend that the ids are British money in the left column,
and French decimals in the right
select id from test_books
order by 1
|
|
No rows retrieved.
rows retrieved.
|
Prove that an empty resultset executes the wasEmpty tag
select id, name, description from test_books
where id > 1000
retrieved row
Description: <%= pageContext.getAttribute("description") %>
[no description]
No rows retrieved.
rows retrieved.
Make sure the rowCount tag works with zero rows, outside a preparedStatement.
rows retrieved.
Closing the database connection
Connection is closed?
Success!