The <dotj:sql> tag can be used to execute SQL against your database. It supports various ways to obtain a
connection to the database, including using a J2EE DataSource (not demonstrated here).
SQL Tag (driver, uri, userid, and password specified):
In this first example, we obtain a connection via a DriverManager using the driver, uri, userid, and password properties.
In our case, these values were first obtained manually (via code) from a properties file. Once the query executes, we
pass the results to a <dotj:grid>. Notice that you can force the use of a PreparedStatement by using the
<dotj:parameter> tags.
Customers (A thru H)
Id
LastName
FirstName
City
State
Zip
Country
Gender
Employed
Comments
Approved
Email
DateOfBirth
15
Chan
Liam
Palm Springs
AZ
47387
AT
M
Y
JTZU
TZ
Y
10
Danns
Allan
Washington DC
DC
04105
MX
M
Y
dfadfadfa
Y
bclinton@worldaids.com
1952-02-11
3
das
dsad
Portland
MO
22151
SA
F
Y
12345ZVSDGASDFASDFASDFSDAF
N
djohns@gmail.com
2006-10-04
2
dfdfd
dfdf
Lincoln
NY
34561
KI
M
N
EEEEA
N
jpardi@comcast.com
2006-10-27
13
Fellows
Bill
Gray
ME
04105
US
M
Y
SSSSSSSS
N
19
Gatez
Jeff
10234
US
M
Y
fffffff
N
4
Gbv
matt
Hollywod
CT
90210
CR
M
Y
cvvc gfg fd dfgdgfdgfdgfdgfdgfg
Y
tgardner@yahoo.com
2006-10-10
8
gcg
prova
Standish
WV
66778
CR
M
Y
TEST FROM BELGIUM
N
SQL Tag (Properties file specified):
In this second example, our connection properties are obtained automatically for us by pointing to a properties file, which
contains each of the connection values.
Customers (I thru P)
Id
LastName
FirstName
City
State
Zip
Country
Gender
Employed
Comments
Approved
Email
DateOfBirth
5
Jackson
xxx
Salem
AR
1234
BV
F
N
EEAASEE EEEEE EEEEE EEEEE EEEEE EEEEE EEEEE EEEEE
N
sroy@hotmail.com
2006-10-19
9
Leno
Jay
Falmouth
NJ
04105
BO
M
N
HAVE A CLUE
Y
gmpardi@maine.rr.com
1998-02-19
14
Lu
Lucy
Billings
FL
42844
US
F
Y
Do it!
N
16
McCartney
Paul
Green Bay
WI
78378
US
M
Y
mayank
N
1
null
null
null
AK
null
NU
n
N
test1
n
bgates@microsoft.com
1957-10-10
6
Obama
barack
Prtland
ME
04101
VN
F
Y
12354
Y
bhoward@cicsco.com
1963-04-15
18
Obama
Barrack Jr.
32419
US
F
Y
customer
Y
SQL Tag (java.sql.Connection specified):
In this last example, we obtain our connection ourselves and let the tag use it. When doing this, the connection is
kept open and it is up to the JSP developer to close the connection.