Java Reference
In-Depth Information
<dataSource type="SIMPLE">
<property name="JDBC.Driver"
value="com.mysql.jdbc.Driver"/>
<property name="JDBC.ConnectionURL"
value="jdbc:mysql://localhost/test"/>
<property name="JDBC.Username"
value="root"/>
<property name="JDBC.Password"
value="blah"/>
</dataSource>
</transactionManager>
<sqlMap resource="SqlMap.xml" />
</sqlMapConfig>
C
Provides name of
built-in transaction
manager
D
Provides your SQL Maps
As you may have guessed, this is where we tell i
BATIS
how to connect to the data-
base and which
SQL
Map files are available. Since it is an
XML
document, we need
to provide a doctype and
DTD
for validation .
SIMPLE
is the name of a built-in
transaction manager . Here is where you provide the name of your
JDBC
driver,
the
JDBC
URL
, a username, and a password that lets you connect to the database.
Then you provide your
SQL
Maps . Here, we only have one
SQL
Map, but you
can have as many as you want. There are a few other things you can do here, but
we cover them all in the next chapter.
Now that you have seen the main configuration file, let's take a look at the
SqlMap.xml
file (listing 2.6). This is the file that contains the
SQL
statement that
we will be running.
B
C
D
Listing 2.6
The simplest SQL Map ever
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap>
<select id="getAllUsers" parameterClass="string"
resultClass="hashmap">
SELECT * FROM USER_ACCOUNT WHERE GROUPNAME = #groupName#
</select>
</sqlMap>
In the
XML
code in listing 2.6, we're accepting a String parameter (
parameter-
Class
) for the
GROUPNAME
parameter, and mapping the results (
resultClass
) to a
HashMap.




















