SlideShare ist ein Scribd-Unternehmen logo
1 von 15
IBatis Get to know iBatis Author: Rohit Prabhakar http://rohitprabhakar.com
Get to know iBatis from Rohit @ http://rohitprabhakar.com iBatis Topics: ,[object Object]
Installation
Environment
Spring-iBatis Integration
SQL Mappings
Conclusion,[object Object]
iBatis: Installation iBATISis delivered in a single JAR file: ibatis-version.build.jarand should be copied and made available at runtime via the application's class path. This can be downloaded from iBatis homepage. Get to know iBatis from Rohit @ http://rohitprabhakar.com
iBatis:Environment Configuration Using Spring - iBATIS with a stand-alone application: ,[object Object]
Define and place the following three configuration files in the classpathSpring config - This file defines the database connection parameters, the location of the SQL Map config file, and one or more Spring beans for use within the application. ( applicationContext.xml).  SQL Map config - This file defines any iBATIS-specific configuration settings that you may need and declares the location for any SQL Map files that should be accessible through this config file. (SqlMapConfig.xml)  SQL Map(s) One or more SQL Map files are declared in the SQL Map config and typically mapped to a single business entity within the application ,often represented by a single Java class (domainObject.xml).  Using Spring - iBATIS with a web application ,[object Object],Get to know iBatis from Rohit @ http://rohitprabhakar.com
Spring-iBatis Integration ,[object Object]
Create a package “com.test.ibatis”
Create a class “Student “package com.test.ibatis; public class Student { private long studentId; private String firstName; private String lastName; private String address; } ,[object Object],Get to know iBatis from Rohit @ http://rohitprabhakar.com
Spring-iBatis Integration ,[object Object],CREATE TABLE STUDENT( STUDENT_ID NUMBER (6, 0) NOT NULL, FIRST_NAME VARCHAR(50) NOT NULL, LAST_NAME VARCHAR(50) , ADDRESS VARCHAR(200) NOT NULL, PRIMARY KEY (STUDENT_ID) ) Get to know iBatis from Rohit @ http://rohitprabhakar.com
Spring-iBatis Integration: applicationContext.xml Add the following <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /> <property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:orcl" /> <property name="username" value="scott" /> <property name="password" value="tiger" /> </bean> <bean id="sqlMap" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"> <property name="configLocation"> <value>classpath:SqlMapConfig.xml</value> </property> <property name="dataSource" ref="dataSource" /> </bean> <bean id="studentService" class="com.test.ibatis.StudentServiceImpl"> <property name="sqlMapClient" ref="sqlMap" /> </bean> Get to know iBatis from Rohit @ http://rohitprabhakar.com

Weitere ähnliche Inhalte

Was ist angesagt?

Hibernate Interview Questions
Hibernate Interview QuestionsHibernate Interview Questions
Hibernate Interview Questions
Syed Shahul
 

Was ist angesagt? (19)

Spring Framework Tutorial | VirtualNuggets
Spring Framework Tutorial | VirtualNuggetsSpring Framework Tutorial | VirtualNuggets
Spring Framework Tutorial | VirtualNuggets
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Introduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoCIntroduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoC
 
Spring framework Introduction
Spring framework IntroductionSpring framework Introduction
Spring framework Introduction
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
Spring notes
Spring notesSpring notes
Spring notes
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
 
Java spring ppt
Java spring pptJava spring ppt
Java spring ppt
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Getting Started with Spring Framework
Getting Started with Spring FrameworkGetting Started with Spring Framework
Getting Started with Spring Framework
 
Spring framework-tutorial
Spring framework-tutorialSpring framework-tutorial
Spring framework-tutorial
 
Spring core module
Spring core moduleSpring core module
Spring core module
 
Spring ppt
Spring pptSpring ppt
Spring ppt
 
Hibernate Interview Questions
Hibernate Interview QuestionsHibernate Interview Questions
Hibernate Interview Questions
 
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of ControlJava Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
 
Spring MVC Framework
Spring MVC FrameworkSpring MVC Framework
Spring MVC Framework
 

Ähnlich wie Introduction to Ibatis by Rohit

Toms introtospring mvc
Toms introtospring mvcToms introtospring mvc
Toms introtospring mvc
Guo Albert
 
Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)
Gunith Devasurendra
 
Intro To Mvc Development In Php
Intro To Mvc Development In PhpIntro To Mvc Development In Php
Intro To Mvc Development In Php
funkatron
 

Ähnlich wie Introduction to Ibatis by Rohit (20)

Toms introtospring mvc
Toms introtospring mvcToms introtospring mvc
Toms introtospring mvc
 
Exploring Symfony's Code
Exploring Symfony's CodeExploring Symfony's Code
Exploring Symfony's Code
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
 
SpringBootCompleteBootcamp.pptx
SpringBootCompleteBootcamp.pptxSpringBootCompleteBootcamp.pptx
SpringBootCompleteBootcamp.pptx
 
Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)
 
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdfdokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf
 
dokumen.tips_rediscovering-spring-with-spring-boot1.pdf
dokumen.tips_rediscovering-spring-with-spring-boot1.pdfdokumen.tips_rediscovering-spring-with-spring-boot1.pdf
dokumen.tips_rediscovering-spring-with-spring-boot1.pdf
 
I Feel Pretty
I Feel PrettyI Feel Pretty
I Feel Pretty
 
Boston Computing Review - Java Server Pages
Boston Computing Review - Java Server PagesBoston Computing Review - Java Server Pages
Boston Computing Review - Java Server Pages
 
Spring data jpa are used to develop spring applications
Spring data jpa are used to develop spring applicationsSpring data jpa are used to develop spring applications
Spring data jpa are used to develop spring applications
 
ActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group PresentationActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group Presentation
 
Apache Aries Blog Sample
Apache Aries Blog SampleApache Aries Blog Sample
Apache Aries Blog Sample
 
Ibm
IbmIbm
Ibm
 
Php frameworks
Php frameworksPhp frameworks
Php frameworks
 
Intro To Mvc Development In Php
Intro To Mvc Development In PhpIntro To Mvc Development In Php
Intro To Mvc Development In Php
 
Springboot2 postgresql-jpa-hibernate-crud-example with test
Springboot2 postgresql-jpa-hibernate-crud-example with testSpringboot2 postgresql-jpa-hibernate-crud-example with test
Springboot2 postgresql-jpa-hibernate-crud-example with test
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Data access
Data accessData access
Data access
 
Introducing Struts 2
Introducing Struts 2Introducing Struts 2
Introducing Struts 2
 
Overview of entity framework by software outsourcing company india
Overview of entity framework by software outsourcing company indiaOverview of entity framework by software outsourcing company india
Overview of entity framework by software outsourcing company india
 

Kürzlich hochgeladen

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Kürzlich hochgeladen (20)

Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

Introduction to Ibatis by Rohit

  • 1. IBatis Get to know iBatis Author: Rohit Prabhakar http://rohitprabhakar.com
  • 2.
  • 7.
  • 8. iBatis: Installation iBATISis delivered in a single JAR file: ibatis-version.build.jarand should be copied and made available at runtime via the application's class path. This can be downloaded from iBatis homepage. Get to know iBatis from Rohit @ http://rohitprabhakar.com
  • 9.
  • 10.
  • 11.
  • 12. Create a package “com.test.ibatis”
  • 13.
  • 14.
  • 15. Spring-iBatis Integration: applicationContext.xml Add the following <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /> <property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:orcl" /> <property name="username" value="scott" /> <property name="password" value="tiger" /> </bean> <bean id="sqlMap" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"> <property name="configLocation"> <value>classpath:SqlMapConfig.xml</value> </property> <property name="dataSource" ref="dataSource" /> </bean> <bean id="studentService" class="com.test.ibatis.StudentServiceImpl"> <property name="sqlMapClient" ref="sqlMap" /> </bean> Get to know iBatis from Rohit @ http://rohitprabhakar.com
  • 16. Spring-iBatis Integration SqlMapConfig.xml As for the configLocation property, it should be configured with the path to an XML file that enumerates the locations of the iBATIS SQL maps. <?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"> <sqlMapConfig> <settings useStatementNamespaces="true" /> <sqlMap resource="StudentSQLMap.xml" /> </sqlMapConfig> Get to know iBatis from Rohit @ http://rohitprabhakar.com
  • 17. Spring-iBatis Integration StudentSQLMap.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 namespace="student"> <typeAlias alias="student" type="com.test.ibatis.Student"/> <resultMap id="studentResult" class="Student"> <result property="studentId" column="STUDENT_ID"/> <result property="firstName" column="FIRST_NAME"/> <result property="lastName" column="LAST_NAME"/> <result property="address" column="ADDRESS"/> </resultMap> <select id="getTrade" parameterClass="long" resultMap="studentResult"> SELECT STUDENT_ID, FIRST_NAME, FIRST_NAME, ADDRESS FROM STUDENT WHERE STUDENT_ID = #id# </select> </sqlMap> Get to know iBatis from Rohit @ http://rohitprabhakar.com
  • 18. Spring-iBatis Integration Create an Interface StudentService package com.test.ibatis; public interface StudentService { public Student getStudent(long studentId) throws Exception; } Get to know iBatis from Rohit @ http://rohitprabhakar.com
  • 19. Spring-iBatis Integration Create an Implementation Class package com.test.ibatis; import com.ibatis.sqlmap.client.SqlMapClient; public class StudentServiceImpl implements StudentService { protected SqlMapClientsqlMapclient=null; public void setSqlMapclient(SqlMapClientsqlMapclient) { this.sqlMapclient = sqlMapclient; } public Student getStudent(long studentId) throws Exception { return (Student) sqlMapclient.queryForObject("student.getStudent", studentId); } } Get to know iBatis from Rohit @ http://rohitprabhakar.com
  • 20. Spring-iBatis Integration: Student Client package com.test.ibatis; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class StudentClient { public static void Main(String[] args) { // load spring beans ApplicationContextctx= new ClassPathXmlApplicationContext("applicationContext.xml"); StudentServicestudentService= (StudentService) ctx.getBean("studentService"); //get Object Student intstudentId=1; try { System.out.println("**********************************"); System.out.println(studentService.getStudent(studentId)); System.out.println("**********************************"); } catch (Exception e) {e.printStackTrace();} } } Get to know iBatis from Rohit @ http://rohitprabhakar.com
  • 21. Spring-iBatis Integration: Execute Run the Client and check what it prints? Get to know iBatis from Rohit @ http://rohitprabhakar.com
  • 22. iBatis: Tools Ibator Ibator is a code generator and Eclipse plugin. It can be used to get a head start on your project by generating your Beans, Mappings and SQL from an existing database schema. Get to know iBatis from Rohit @ http://rohitprabhakar.com