|
MollyPages.org
"You were wrong case. To live here is to live." |
Pages /
Database /
Forms /
Servlet /
Javadocs
/
License & Download /
Tutorials /
Cookbook
/
Contact & Hire
|
[[ ..java code here (can be any number of lines).. ]]
The code section prints the value of a java variable using the variable "out" (which is a PrintWriter that writes to the output stream of the page).
out.println(..) statements but are easier to
write. (These are called Hash sections).
| Dream ");
out.print(n);
out.print(" grows like slow ice  ");
for (int k = 0; k < n; k++) {
out.print(" |
Dream 1 grows like slow ice ![]() |
Dream 2 grows like slow ice ![]() ![]() |
Dream 3 grows like slow ice ![]() ![]() ![]() |
Dream 4 grows like slow ice ![]() ![]() ![]() ![]() |
Dream 5 grows like slow ice ![]() ![]() ![]() ![]() ![]() |
out.println()
Dream [=n] grows like slow ice #
for (int k = 0; k < n; k++) {
# #
}
# |
The test table referenced by this code was created as follows:
sql> create table test (a varchar(10));
sql> insert into test (a) values ('hello');
sql> insert into test (a) values ('world');
Note, this example also uses import and method declaration sections.
[import
import java.sql.*;
import java.util.*;
]
[!
//method declaration block
Connection getConnection() {
//implement this method
}
!]
[[
//about to start page rendering
Connection con = null;
try
{
con = getConnection();
]]
<html>
<body>
<table border=1>
[[
PreparedStatement ps=con.prepareStatement(
"select * from test");
ResultSet rs = ps.executeQuery();
while (rs.next()) {
#<tr><td>[=rs.getString(1)]</td></tr>#
}
]]
</body>
</html>
[[
} //~end outermost try block
finally {
try { con.close(); }
catch (SQLException e) { /* log..*/ }
}
]]
| hello |
| world |