I'm currently trying to setup ibatis for the first time.
I copied the SqlMapConfig.xml from the tutorial, tweaked the jdbc connection parameter to
match my environment, copied the Person.xml from the tutorial, created the person table in
the database and then tried to start a simple query as in the tutorial.
But iBatis throws a "org.xml.sax.SAXParseException: Document root element is missing" at startup
time..
Does anybody know what's going wrong here? My environment is JDK 1.4.2_07.
Here are both xml-Files.
SqlMapConfig.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMapConfig
PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"
"http://www.ibatis.com/dtd/sql-map-config-2.dtd">
<!-- Always ensure to use the correct XML header as above! -->
<sqlMapConfig>
<transactionManager type="JDBC" >
<dataSource type="SIMPLE">
<property name="JDBC.Driver" value="<myDriver>"/>
<property name="JDBC.ConnectionURL" value="<myUrl>"/>
<property name="JDBC.Username" value="<myUser>"/>
<property name="JDBC.Password" value="<myPassword>"/>
</dataSource>
</transactionManager>
<!-- Identify all SQL Map XML files to be loaded by this SQL map. Notice the paths
are relative to the classpath. For now, we only have one -->
<sqlMap resource="Person.xml" />
</sqlMapConfig>
Person.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap
PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
"http://www.ibatis.com/dtd/sql-map-2.dtd">
<sqlMap>
<select id="getPerson" resultClass="examples.domain.Person">
SELECT
PER_ID as id,
PER_FIRST_NAME as firstName,
PER_LAST_NAME as lastName,
PER_BIRTH_DATE as birthDate,
PER_WEIGHT_KG as weightInKilograms,
PER_HEIGHT_M as heightInMeters
FROM PERSON
WHERE PER_ID = #value#
</select>
</sqlMap>
Testprog:
import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
public class AppSqlConfig {
private SqlMapClient sqlMap = null;
public static void main(String[] args) {
new AppSqlConfig().run();
}
public void run() {
try {
String resource = "SqlMapConfig.xml";
Reader reader = Resources.getResourceAsReader (resource);
sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
Integer personPk = new Integer(5);
Person person = (Person) sqlMap.queryForObject ("getPerson", personPk);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
/Axel
|