iBatis Tutorial Part 2 – SQLMapConfig.xml Basics

August 13th, 2008 by admin Leave a reply »

This is where you need to provide all configurations for iBatis. Create an XML file with name SqlMapConfig.xml


<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE sqlMapConfig PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN" "
http://ibatis.apache.org/dtd/sql-map-config-2.dtd
">

<sqlMapConfig>

<transactionManager type="JDBC">

<dataSource type="SIMPLE">

<property name="JDBC.Driver" value="com.mysql.jdbc.Driver"/>

<property name="JDBC.ConnectionURL" value="jdbc:mysql://localhost:3306/testdb"/>

<property name="JDBC.Username" value="root"/> <property name="JDBC.Password"

value=""/>

</dataSource>

</transactionManager>

<sqlMap resource="com/Employee.xml"/> </sqlMapConfig>


Lets understand the above code :

<transactionManager type=”JDBC”>

type can be JDBC, JTA,External

JDBC Alias for com.ibatis.sqlmap.engine.transaction.jdbc.JdbcTrasactionConfig

JTA alias for com.ibatis.sqlmap.engine.transaction.jta.JtaTransactionConfig

External alias for com.ibatis.sqlmap.engine.transaction.external.ExternalTransactionConfig


<dataSource type=”SIMPLE”>

datasouce can be SIMPLE, DBCP, JNDI

SIMPLE is an alias for com.ibatis.sqlmap.engine.datasource.

SimpleDataSourceFactory DBCP is an alias for com.ibatis.sqlmap.engine.datasource.

DbcpDataSourceFactory JNDI is an alias for com.ibatis.sqlmap.engine.datasource.JndiDataSourceFactory.


While using JNDI :

Use the following code

<dataSource type=”JNDI”>

<transactionManager type="JTA">

<property name = "UserTransaction" value ="java:/emp/EmlpoyeeTransaction" />

<datasource type ="JNDI" > <property name ="DataSource" value ="java:/comp

/Employee" />

<datasource>

</transactionManager>

* <property name = "UserTransaction" is optional


DataSource properties :

<property name="JDBC.Driver" value="com.mysql.jdbc.Driver"/>

provide the driverName

<property name="JDBC.ConnectionURL" value="jdbc:mysql://localhost:3306/testdb"/>

provide the connection URL

<property name="JDBC.Username" value="root"/>

<property name="JDBC.Password" value=""/>

provide the username and password

Optional properties

<property name="JDBC.AutoCommit" value="true"/>

<property name="Pool.MaximumActiveConnections" value="10"/>

<property name="Pool.MaximumIdleConnections" value="5"/>

<property name="Pool.MaximumCheckoutTime" value="100000"/>

<property name="Pool.MaximumTimeToWait" value="400"/>

<property name="Pool.PingQuery" value="select 1 from Enployee"/>

<property name="Pool.PingEnabled" value="false"/>


<sqlMap resource="com/Employee.xml"/>

Used to add the xml where the sql queries have been written in another XML file . Should be present in the class path. Alternatively to load files from a URL <sqlMap url="file://c:/Employee/Employee.xml"/> Related Articles:

Introduction to IBatis Tutorial -Part 3

IBatis vs Hibernate ? Which one to choose?

Related Posts with Thumbnails

Advertisement

24 comments

  1. Hidden due to low comment rating. Click here to see.

    Poorly-rated. Like or Dislike: Thumb up 0 Thumb down 3

  2. Hidden due to low comment rating. Click here to see.

    Poorly-rated. Like or Dislike: Thumb up 0 Thumb down 3

  3. Just what I needed to take the edge off after a intense day. Excellent writing that really gets the point across. Thank you for sharing.

    Like or Dislike: Thumb up 0 Thumb down 2

  4. Hidden due to low comment rating. Click here to see.

    Poorly-rated. Like or Dislike: Thumb up 0 Thumb down 3

  5. Hidden due to low comment rating. Click here to see.

    Poorly-rated. Like or Dislike: Thumb up 0 Thumb down 3

  6. EdgarLO says:

    Hidden due to low comment rating. Click here to see.

    Poorly-rated. Like or Dislike: Thumb up 0 Thumb down 3

  7. Amazing Dude, I didn’t knew that, thanks.

    Like or Dislike: Thumb up 0 Thumb down 1

  8. Marc Curreri says:

    Looks like these guys have plenty of outsourcing opportunities available.

    Like or Dislike: Thumb up 0 Thumb down 2

  9. Thanks!

    Like or Dislike: Thumb up 0 Thumb down 1

  10. Keep on blogging! its getting through the tough times that make you stronger and then the good times will follow, keep writing about your experiences and we should all pull together.

    Like or Dislike: Thumb up 0 Thumb down 2

  11. ochrona says:

    Yes, that is true, I agree with you, but I am not sure if there are no other options.

    Like or Dislike: Thumb up 0 Thumb down 0

  12. Keep up the good writing

    Like or Dislike: Thumb up 0 Thumb down 1

  13. Mozelle Hayn says:

    Your post caught my eye. Thanks for posting this information.

    Like or Dislike: Thumb up 0 Thumb down 1

  14. free gadgets says:

    I was just searching google and found your blog, very nice read.

    Like or Dislike: Thumb up 0 Thumb down 0

  15. I completely agree with the above comment, the internet is with a doubt growing into the most important medium of communication across the globe and its due to sites like this that ideas are spreading so quickly.

    Like or Dislike: Thumb up 0 Thumb down 0

  16. Shela Graven says:

    Really nice article! Your writing is so fresh in comparison to most other bloggers. Thank you for posting when you get the chance to, I’ll be sure to subscribe!

    Like or Dislike: Thumb up 0 Thumb down 0

  17. Great info, thanks for useful article. I am waiting for more

    Like or Dislike: Thumb up 0 Thumb down 0

  18. Thank you for another informative blog. Where else could I get that kind of info written in such a perfect way? I have a project that I am just now working on, and I have been on the look out for such information.

    Like or Dislike: Thumb up 0 Thumb down 0

  19. Bradly Avona says:

    hey,Superb article dude! i am Tired of using RSS feeds and do you use twitter?so i can follow you there:D.
    PS:Do you thought to be putting video to the blog to keep the readers more interested?I think it works.Best regards, Bradly Avona

    Like or Dislike: Thumb up 0 Thumb down 0

  20. gumpert says:

    nice copy of the ibatis documentation. do you plan to stop commenting/cheering your own blog?

    Like or Dislike: Thumb up 0 Thumb down 0

  21. Tobias Norg says:

    Hi there, awesome site. I thought the topics you posted on were very interesting

    Like or Dislike: Thumb up 0 Thumb down 0

  22. Hi there may I use some of the information here in this post if I provide a link back to your site?

    Like or Dislike: Thumb up 0 Thumb down 0

  23. I precisely wished to appreciate you once more. I’m not certain the things that I could possibly have accomplished in the absence of the type of suggestions shared by you directly on such a situation. Completely was a real daunting matter for me personally, however , looking at a skilled avenue you handled it forced me to weep over joy. I’m just thankful for your work as well as pray you find out what a powerful job you are always putting in instructing men and women using your webblog. I’m certain you’ve never got to know all of us.

    Like or Dislike: Thumb up 0 Thumb down 0

Leave a Reply