{"id":1793,"date":"2012-09-18T12:53:14","date_gmt":"2012-09-18T12:53:14","guid":{"rendered":"http:\/\/www.mobisoftinfotech.com\/blog\/?p=1793"},"modified":"2024-11-18T15:56:49","modified_gmt":"2024-11-18T10:26:49","slug":"blog-on-mybatis","status":"publish","type":"post","link":"https:\/\/mobisoftinfotech.com\/resources\/blog\/web-programming\/blog-on-mybatis","title":{"rendered":"Configuring MyBatis 3 With MySQL In Java Projects"},"content":{"rendered":"<h2><b>What is MyBatis?<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">MyBatis is a Higher version of iBatis. Its lightweight persistence framework which is mapping SQL databases and objects in Java, .NET, and Ruby on Rails.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">MyBatis support for custom SQL, Views, advanced mappings, stored procedures and declarative data caching.It is the new version of the iBatis Data Mapper Java Framework, which allows you to use a relational database with object-oriented applications.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In single line, we can describe MyBatis as a SQL Mapping Framework for Java, .NET and Ruby on Rails.<\/span><\/p>\n<h2><b>MyBatis Design Aspects:<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">MyBatis comes with the following design aspects:<\/span><\/p>\n<ul>\n<li><span style=\"font-weight: 400;\"><strong>Simplicity:<\/strong> <br>MyBatis is widely considered as the simplest persistence framework.<\/span><\/li>\n<li><span style=\"font-weight: 400;\"><strong>Fast Development:<\/strong> <br>MyBatis&#8217;s aspects is useful to facilitate hyper-fast.<\/span><\/li>\n<li><span style=\"font-weight: 400;\"><strong>Portability:<\/strong> \n<br>MyBatis can be implemented for almost all language or platform like Java, Ruby, and C# for Microsoft .NET.<\/span><\/li>\n<li><span style=\"font-weight: 400;\"><strong>Independent Interfaces:<\/strong><br> It provides database-independent interfaces and APIs that help the rest of the application remain independent of any persistence-related resources.<\/span><\/li>\n<li><span style=\"font-weight: 400;\"><strong>Open Source:<\/strong><br> Its free and an open source software.<\/span><\/li>\n<\/ul>\n\n<h2><b>Why MyBatis?<\/b><\/h2>\n<p><span style=\"font-weight: 400;\"> As we all are familier with today&#8217;s market conditions.A lot of freamworks are available for Database Mapping Architecrture like Hibernet then surely one question must comes into mind why we use MyBatis?<\/span><br><span style=\"font-weight: 400;\">If we observe following few suitiations then we got the answer.<\/span><br><span style=\"font-weight: 400;\">Suppose if<\/span><br>\n<\/p><ul><li>\n<span style=\"font-weight: 400;\"> you want to create your own SQL&#8217;s and are willing to maintain them,<\/span><\/li><li><span style=\"font-weight: 400;\"> your environment is driven by relational data model,<\/span><\/li><li><span style=\"font-weight: 400;\"> you have to work existing and complex schema&#8217;s<\/span><\/li><\/ul><span style=\"font-weight: 400;\">then positively MyBatis is a better solution.<\/span>\n<p><span style=\"font-weight: 400;\">Also If you are using stored procedures, well you can do it in Hibernate but it is little difficult in comparision of MyBatis. As an alternative solution MyBatis maps results sets to objects, so no need to care about table structures.<\/span><\/p>\n<h2><b>Prepare a Database for sample example:<\/b><\/h2>\n<ul>\n<li>\n<p><span style=\"font-weight: 400;\"> Start MySQL Server to prepare database.<\/span><\/p>\n<\/li>\n<li>\n<p><span style=\"font-weight: 400;\"> Run following queries in MySQL using command prompt or IDE like SQLyog or PhpMyAdmin.<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">CREATE DATABASE IF NOT EXISTS studentdb;<\/span>\n\n<span style=\"font-weight: 400;\">USE studentdb;<\/span>\n\n<span style=\"font-weight: 400;\">\/*Table structure for table Student *\/<\/span>\n\n<span style=\"font-weight: 400;\">DROP TABLE IF EXISTS Student;<\/span>\n\n<span style=\"font-weight: 400;\">CREATE TABLE Student (<\/span>\n<span style=\"font-weight: 400;\">rollNo INT(11) NOT NULL AUTO_INCREMENT,<\/span>\n<span style=\"font-weight: 400;\">studentName VARCHAR(30) DEFAULT NULL,<\/span>\n<span style=\"font-weight: 400;\">marks INT(11) DEFAULT NULL,<\/span>\n<span style=\"font-weight: 400;\">PRIMARY KEY (rollNo)<\/span>\n<span style=\"font-weight: 400;\">);<\/span>\n\n<span style=\"font-weight: 400;\">\/*Data for the table Student *\/<\/span>\n\n<span style=\"font-weight: 400;\">INSERT INTO Student(rollNo,studentName,marks) VALUES (1,'John P',82),(2,'Abdul K',94),(3,'Raju S',35);<\/span><\/pre>\n<\/li>\n<\/ul>\n<h2><b>Let&#8217;s get started:<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">To see how Tomcat, MyBatis and MySQL work together we&#8217;re going to create a small java application in Eclipse called \u201cMyBatisDemo\u201d.You can download the Sample Project <a href=\"https:\/\/www.mobisoftinfotech.com\/resources\/wp-content\/uploads\/2012\/09\/MyBatisDemo.zip\">Here<\/a>.<\/span><\/p>\n<ul>\n<li><span style=\"font-weight: 400;\">Create New Java Project in Eclipse named as \u201cMyBatisDemo\u201d.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Create new folder under project named as \u201clib\u201d for external jar files.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Now create a new package structure like &#8211;<\/span><br><span style=\"font-weight: 400;\">com.batis.mybatisdao<\/span><br><span style=\"font-weight: 400;\">com.batis.mybatisdao.tests<\/span><br><span style=\"font-weight: 400;\">com.batis.mybatisdao.tests.dao<\/span><br><span style=\"font-weight: 400;\">com.batis.mybatisdao.tests.model<\/span><br><span style=\"font-weight: 400;\">Now your eclipse project structure look like a following screens-<\/span><br>\n<p style=\"text-align: center;\"><a href=\"http:\/\/https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2012\/09\/packageStructure.png\"><noscript><img decoding=\"async\" class=\"aligncenter size-large wp-image-1897\" src=\"http:\/\/https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2012\/09\/packageStructure-e1347968283638-1024x819.png\" alt width=\"680\" height=\"544\" srcset=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2012\/09\/packageStructure-e1347968283638-1024x819.png 1024w, https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2012\/09\/packageStructure-e1347968283638-300x240.png 300w, https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2012\/09\/packageStructure-e1347968283638.png 1280w\" sizes=\"(max-width: 680px) 100vw, 680px\"><\/noscript><img decoding=\"async\" class=\"aligncenter size-large wp-image-1897 lazyload\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20680%20544%22%3E%3C%2Fsvg%3E\" alt width=\"680\" height=\"544\" srcset=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20680%20544%22%3E%3C%2Fsvg%3E 680w\" sizes=\"(max-width: 680px) 100vw, 680px\" data-srcset=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2012\/09\/packageStructure-e1347968283638-1024x819.png 1024w, https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2012\/09\/packageStructure-e1347968283638-300x240.png 300w, https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2012\/09\/packageStructure-e1347968283638.png 1280w\" data-src=\"http:\/\/https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2012\/09\/packageStructure-e1347968283638-1024x819.png\"><\/a><\/p><\/li>\n<li><span style=\"font-weight: 400;\"> Configuration XML &#8211; Create \u201cmybatisConfig.xml\u201d under src folder.<\/span>\n<p><span style=\"font-weight: 400;\">Consider the following:<\/span><br>\n<\/p><ul><li><span style=\"font-weight: 400;\"> We are going to use JDBC to access the database studentdb.<\/span><br><\/li><li><span style=\"font-weight: 400;\"> JDBC driver for MySQL is &#8220;com.mysql.jdbc.Driver&#8221;.<\/span><br><\/li><li><span style=\"font-weight: 400;\"> Connection URL is &#8220;jdbc:mysql:\/\/localhost:3306\/studentdb&#8221;.<\/span><br><\/li><li><span style=\"font-weight: 400;\"> We would use username and password is &#8220;root&#8221; and &#8220;mobisoft\".<\/span><br><\/li><li><span style=\"font-weight: 400;\"> Our sql statement mappings for all the operations.<\/span><br><\/li><\/ul><span style=\"font-weight: 400;\"> Based on the above assumption we have to create an XML configuration file with name as mybatisConfig.xml with the following content.<\/span>\n<pre>[xml]\n&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;?xml version=&amp;amp;amp;amp;amp;quot;1.0&amp;amp;amp;amp;amp;quot; encoding=&amp;amp;amp;amp;amp;quot;UTF-8&amp;amp;amp;amp;amp;quot; ?&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;\n&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;!DOCTYPE configuration PUBLIC &amp;amp;amp;amp;amp;quot;-\/\/mybatis.org\/\/DTD Config 3.0\/\/EN&amp;amp;amp;amp;amp;quot;&amp;amp;amp;amp;amp;quot;http:\/\/mybatis.org\/dtd\/mybatis-3-config.dtd&amp;amp;amp;amp;amp;quot;&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;\n&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;configuration&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;\n&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;properties resource=&amp;amp;amp;amp;amp;quot;dbcp.properties&amp;amp;amp;amp;amp;quot;\/&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;\n&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;settings&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;\n&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;setting name=&amp;amp;amp;amp;amp;quot;useGeneratedKeys&amp;amp;amp;amp;amp;quot; value=&amp;amp;amp;amp;amp;quot;true&amp;amp;amp;amp;amp;quot;\/&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;\n&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;\/settings&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;\n&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;typeAliases&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;\n&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;typeAlias alias=&amp;amp;amp;amp;amp;quot;Student&amp;amp;amp;amp;amp;quot; type=&amp;amp;amp;amp;amp;quot;com.batis.mybatisdao.tests.model.Student&amp;amp;amp;amp;amp;quot;\/&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;\n&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;\/typeAliases&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;\n&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;environments default=&amp;amp;amp;amp;amp;quot;mobisoft&amp;amp;amp;amp;amp;quot;&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;\n&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;environment id=&amp;amp;amp;amp;amp;quot;mobisoft&amp;amp;amp;amp;amp;quot;&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;\n&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;transactionManager type=&amp;amp;amp;amp;amp;quot;JDBC&amp;amp;amp;amp;amp;quot;\/&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;\n&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;dataSource type=&amp;amp;amp;amp;amp;quot;POOLED&amp;amp;amp;amp;amp;quot;&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;\n&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;property name=&amp;amp;amp;amp;amp;quot;driver&amp;amp;amp;amp;amp;quot; value=&amp;amp;amp;amp;amp;quot;${db.driver}&amp;amp;amp;amp;amp;quot;\/&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;\n&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;property name=&amp;amp;amp;amp;amp;quot;url&amp;amp;amp;amp;amp;quot; value=&amp;amp;amp;amp;amp;quot;${db.url}&amp;amp;amp;amp;amp;quot;\/&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;\n&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;property name=&amp;amp;amp;amp;amp;quot;username&amp;amp;amp;amp;amp;quot; value=&amp;amp;amp;amp;amp;quot;${db.user}&amp;amp;amp;amp;amp;quot;\/&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;\n&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;property name=&amp;amp;amp;amp;amp;quot;password&amp;amp;amp;amp;amp;quot; value=&amp;amp;amp;amp;amp;quot;${db.pass}&amp;amp;amp;amp;amp;quot;\/&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;\n&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;\/dataSource&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;\n&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;\/environment&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;\n&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;\/environments&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;\n&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;mappers&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;\n&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;mapper resource=&amp;amp;amp;amp;amp;quot;com\/batis\/mybatisdao\/tests\/model\/StudentMapper.xml&amp;amp;amp;amp;amp;quot; \/&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;\n&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;\/mappers&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;\n&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;\/configuration&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;\n\n[\/xml]<\/pre>\n<p>Based on the mybatisConfig.xml file we have to create an properties file with name as dbcp.properties file on same location for database credentials with the following content.<\/p>\n<pre>db.url=<span style=\"color: #0000ff;\">jdbc:mysql:\/\/localhost\/studentdb<\/span>\ndb.driver=<span style=\"color: #0000ff;\">com.mysql.jdbc.Driver<\/span>\ndb.user=<span style=\"color: #0000ff;\">root<\/span>\ndb.pass=<span style=\"color: #0000ff;\">mobisoft<\/span><\/pre>\n<\/li><li data-tadv-p=\"keep\"><strong> Student POJO Class:<\/strong><br>\n<p>Based on the Following POJO Class specification, the following class has 3 properties: rollNo, studentName, and marks. These match up exactly with the column names in the select statement in XML Mapper File.<br>Now create one class under com.batis.mybatisdao.tests.model package named as \u201cStudent\u201d with the following content.<\/p>\n<pre>[java]\n\npackage com.batis.mybatisdao.tests.model;\n\npublic class Student {\nprivate int rollNo;\nprivate String studentName;\nprivate int marks;\n\npublic int getRollNo() {\n     return rollNo;\n}\n\npublic void setRollNo(int rollNo) {\n   this.rollNo = rollNo;\n}\n\npublic String getStudentName() {\n     return studentName;\n}\n\npublic void setStudentName(String studentName) {\n     this.studentName = studentName;\n}\n\npublic int getMarks() {\n    return marks;\n}\n\npublic void setMarks(int marks) {\n   this.marks = marks;\n}\n\n@Override\npublic String toString() {\n     return &amp;amp;amp;amp;amp;quot;[Status] &amp;amp;amp;amp;amp;quot; + &amp;amp;amp;amp;amp;quot;(&amp;amp;amp;amp;amp;quot; + rollNo + &amp;amp;amp;amp;amp;quot;) &amp;amp;amp;amp;amp;quot; + studentName + &amp;amp;amp;amp;amp;quot; Marks : &amp;amp;amp;amp;amp;quot;+marks ;\n}\n}\n[\/java]<\/pre>\n<\/li>\n<li data-tadv-p=\"keep\"><strong> XML Mapper File:<\/strong><br>Now its time to wirte a mapper file of Student POJO Class which is useful for CRUD Operations of Student records from Database. Create new xml file under com.batis.mybatisdao.tests.model package named as \u201cStudentMapper.xml\u201d with the following content.\n<pre>[xml]\n&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;?xml version=&amp;amp;amp;amp;amp;quot;1.0&amp;amp;amp;amp;amp;quot; encoding=&amp;amp;amp;amp;amp;quot;UTF-8&amp;amp;amp;amp;amp;quot; ?&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;\n&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;!DOCTYPE mapper PUBLIC &amp;amp;amp;amp;amp;quot;-\/\/mybatis.org\/\/DTD Mapper 3.0\/\/EN&amp;amp;amp;amp;amp;quot; &amp;amp;amp;amp;amp;quot;http:\/\/mybatis.org\/dtd\/mybatis-3-mapper.dtd&amp;amp;amp;amp;amp;quot;&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;\n\n&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;mapper namespace=&amp;amp;amp;amp;amp;quot;mobisoft&amp;amp;amp;amp;amp;quot;&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;\n\n\t&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;select id=&amp;amp;amp;amp;amp;quot;getAllStudent&amp;amp;amp;amp;amp;quot; parameterType=&amp;amp;amp;amp;amp;quot;int&amp;amp;amp;amp;amp;quot; resultType=&amp;amp;amp;amp;amp;quot;Student&amp;amp;amp;amp;amp;quot;&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;\n\t\tselect rollNo as &amp;amp;amp;amp;amp;quot;rollNo&amp;amp;amp;amp;amp;quot;, studentName as &amp;amp;amp;amp;amp;quot;studentName&amp;amp;amp;amp;amp;quot;, marks as &amp;amp;amp;amp;amp;quot;marks&amp;amp;amp;amp;amp;quot;\n\t\tfrom studentdb.Student order by rollNo\n\t&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;\/select&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;\n\n\t&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;insert id=&amp;amp;amp;amp;amp;quot;createStudent&amp;amp;amp;amp;amp;quot; keyColumn=&amp;amp;amp;amp;amp;quot;rollNo&amp;amp;amp;amp;amp;quot; useGeneratedKeys=&amp;amp;amp;amp;amp;quot;true&amp;amp;amp;amp;amp;quot; parameterType=&amp;amp;amp;amp;amp;quot;Student&amp;amp;amp;amp;amp;quot;&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;\n\t\tinsert into studentdb.Student (studentName, marks)\n\t\tvalues (#{studentName}, #{marks})\n\t&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;\/insert&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;\n\n\t&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;update id=&amp;amp;amp;amp;amp;quot;updateStudent&amp;amp;amp;amp;amp;quot; parameterType=&amp;amp;amp;amp;amp;quot;Student&amp;amp;amp;amp;amp;quot;&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;\n\t\tupdate studentdb.Student set studentName = #{studentName}, marks = #{marks}\n\t\twhere rollNo = #{rollNo}\n\t&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;\/update&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;\n\n\t&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;delete id=&amp;amp;amp;amp;amp;quot;deleteStudent&amp;amp;amp;amp;amp;quot; parameterType=&amp;amp;amp;amp;amp;quot;int&amp;amp;amp;amp;amp;quot;&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;\n\t\tdelete from studentdb.Student where rollNo = #{rollNo}\n\t&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;\/delete&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;\n&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;\/mapper&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;\n[\/xml]<\/pre>\n<\/li>\n<li>\n<p><strong> Creating DAO Class:<\/strong><\/p>\n<p>Now create One Dao Class under the com.batis.mybatisdao.tests.dao package named as \u201cStudentDao\u201d with the following content to acces generic methods from MyBatis framework. Its a simple example DAO which uses the MyBatisDAO Framework.<\/p>\n<pre>[java]\npackage com.batis.mybatisdao.tests.dao;\n\nimport org.apache.ibatis.session.SqlSessionFactory;\n\nimport com.batis.mybatisdao.JdbcBaseBatisDAO;\nimport com.batis.mybatisdao.tests.model.Student;\n\npublic class StudentDAO extends JdbcBaseBatisDAO&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;Student, Integer&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt; {\n\n    public StudentDAO(SqlSessionFactory containerSessionFactory) {\n\t   super(containerSessionFactory);\n    }\n}\n\n[\/java]<\/pre>\n<\/li>\n<li>\n<p><strong> Implementation of Basic Interface for POJO&#8217;s:<\/strong><\/p>\n<p>Here we implement one generic interface through which we can access any defined method for any type of objects.<br>Now create new interface under the com.batis.mybatisdao package named as \u201cBaseBatisDao\u201d with the following content &#8211;<\/p>\n<pre>[java]\npackage com.batis.mybatisdao;\n\nimport java.util.ArrayList;\n\nimport org.apache.ibatis.exceptions.PersistenceException;\n\npublic interface BaseBatisDao&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;Obj, PK&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;{\n\tpublic ArrayList&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;Obj&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt; getAllStudentList() throws PersistenceException;\n\tpublic int insertStudent(Obj student) throws PersistenceException;\n\tint updateStudentDetails(Obj student) throws PersistenceException;\n\tint deleteStudentFromDB(PK rollNo) throws PersistenceException;\n}\n\n[\/java]<\/pre>\n<\/li>\n<li>\n<p><strong> Implementation of Jdbc Class:<\/strong><\/p>\n<p>It is a abstract class through which we can implements above generic interface for implementation of all define methods in interface.<br>Now create new abstract class under the com.batis.mybatisdao package named as \u201cJdbcBaseBatisDAO\u201d with the following content &#8211;<\/p>\n<pre>[java]\npackage com.batis.mybatisdao;\n\nimport java.util.ArrayList;\n\nimport org.apache.ibatis.exceptions.PersistenceException;\nimport org.apache.ibatis.session.SqlSession;\nimport org.apache.ibatis.session.SqlSessionFactory;\nimport org.apache.log4j.Logger;\n\npublic abstract class JdbcBaseBatisDAO&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;Obj, PK&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt; implements BaseBatisDao&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;Obj, PK&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt; {\n\n    private static Logger log = Logger.getLogger(JdbcBaseBatisDAO.class);\n    private static final String NAMESPACE = &amp;amp;amp;amp;amp;quot;mobisoft&amp;amp;amp;amp;amp;quot;;\n\n    private SqlSessionFactory sqlSessionFactory;\n\n    public static final String PREFIX_SELECT_QUERY = &amp;amp;amp;amp;amp;quot;get&amp;amp;amp;amp;amp;quot;;\n    public static final String PREFIX_INSERT_QUERY = &amp;amp;amp;amp;amp;quot;create&amp;amp;amp;amp;amp;quot;;\n    public static final String PREFIX_UPDATE_QUERY = &amp;amp;amp;amp;amp;quot;update&amp;amp;amp;amp;amp;quot;;\n    public static final String PREFIX_DELETE_QUERY = &amp;amp;amp;amp;amp;quot;delete&amp;amp;amp;amp;amp;quot;;\n\n   public JdbcBaseBatisDAO(SqlSessionFactory sf) {\n\tthis.sqlSessionFactory = sf;\n\tif (sf == null)\n\t    log.error(&amp;amp;amp;amp;amp;quot;Error: sessionFactory loading failed.&amp;amp;amp;amp;amp;quot;);\n    }\n\n    @SuppressWarnings(&amp;amp;amp;amp;amp;quot;unchecked&amp;amp;amp;amp;amp;quot;)\n    public ArrayList&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;Obj&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt; getAllStudentList() throws PersistenceException {\n\n\tSqlSession session = sqlSessionFactory.openSession();\n\tArrayList&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;Obj&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt; studentList = null;\n\ttry {\n\t    String query = NAMESPACE + &amp;amp;amp;amp;amp;quot;.&amp;amp;amp;amp;amp;quot; + PREFIX_SELECT_QUERY + &amp;amp;amp;amp;amp;quot;AllStudent&amp;amp;amp;amp;amp;quot;;\n\t     studentList = (ArrayList&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;Obj&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;) session.selectList(query);\n\t} finally {\n\t    session.close();\n\t}\n\treturn studentList;\n    }\n\n    public int insertStudent(Obj student) throws PersistenceException {\n\tSqlSession session = sqlSessionFactory.openSession();\n\tInteger rollNo = null;\n\ttry {\n\t    String query = NAMESPACE + &amp;amp;amp;amp;amp;quot;.&amp;amp;amp;amp;amp;quot; + PREFIX_INSERT_QUERY + &amp;amp;amp;amp;amp;quot;Student&amp;amp;amp;amp;amp;quot;;\n\t    rollNo = (Integer) session.insert(query, student);\n\t    session.commit();\n\t} finally {\n\t    session.close();\n\t}\n\treturn rollNo;\n    }\n\n    public int updateStudentDetails(Obj student) throws PersistenceException {\n\n\tSqlSession session = sqlSessionFactory.openSession();\n\tInteger rollNo = null;\n\ttry {\n\t    String query = NAMESPACE + &amp;amp;amp;amp;amp;quot;.&amp;amp;amp;amp;amp;quot; + PREFIX_UPDATE_QUERY + &amp;amp;amp;amp;amp;quot;Student&amp;amp;amp;amp;amp;quot;;\n\t    rollNo = session.update(query, student);\n\t    session.commit();\n\n\t} finally {\n\t    session.close();\n\t}\n\treturn rollNo;\n    }\n\n    public int deleteStudentFromDB(PK rollNo) throws PersistenceException {\n\tSqlSession session = sqlSessionFactory.openSession();\n\tInteger status = null;\n\ttry {\n\t    String query = NAMESPACE + &amp;amp;amp;amp;amp;quot;.&amp;amp;amp;amp;amp;quot; + PREFIX_DELETE_QUERY + &amp;amp;amp;amp;amp;quot;Student&amp;amp;amp;amp;amp;quot;;\n\t    status = session.delete(query, rollNo);\n\t    session.commit();\n\t} finally {\n\t    session.close();\n\t}\n\treturn status;\n    }\n}\n\n[\/java]<\/pre>\n<\/li>\n<li>\n<p><strong> Create Testing MyBatis Demo class:<\/strong><\/p>\n<p>Now create new class under the com.batis.mybatisdao.tests package named as \u201c<strong>TestStudentDAO<\/strong>\u201d with the following content to test the MyBatis Demo which we create till now.<\/p>\n<pre>[java]\npackage com.batis.mybatisdao.tests;\n\nimport java.io.Reader;\nimport java.util.ArrayList;\n\nimport org.apache.ibatis.io.Resources;\nimport org.apache.ibatis.session.SqlSessionFactory;\nimport org.apache.ibatis.session.SqlSessionFactoryBuilder;\nimport org.apache.log4j.Logger;\nimport org.junit.BeforeClass;\nimport org.junit.Test;\n\nimport com.batis.mybatisdao.tests.dao.StudentDAO;\nimport com.batis.mybatisdao.tests.model.Student;\n\npublic class TestStudentDAO {\n\n    private static Logger log = Logger.getLogger(TestStudentDAO.class);\n    private static SqlSessionFactory sf;\n    private static StudentDAO studentDao;\n\n    @BeforeClass\n    public static void setUp() throws Exception {\n\n\tlog.info(&amp;amp;amp;amp;amp;quot; Mybatis setup is in progress...&amp;amp;amp;amp;amp;quot;);\n\tString resource = &amp;amp;amp;amp;amp;quot;mybatisConfig.xml&amp;amp;amp;amp;amp;quot;;\n\tReader reader = Resources.getResourceAsReader(resource);\n\tsf = new SqlSessionFactoryBuilder().build(reader, &amp;amp;amp;amp;amp;quot;mobisoft&amp;amp;amp;amp;amp;quot;);\n\tstudentDao = new StudentDAO(sf);\n\tlog.info(&amp;amp;amp;amp;amp;quot; Connection Established Successfully.&amp;amp;amp;amp;amp;quot;);\n    }\n\n    @Test\n    public static void getAllStudents() {\n\n\tArrayList&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;Student&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt; list = studentDao.getAllStudentList();\n\tlog.info(&amp;amp;amp;amp;amp;quot;Student List: &amp;amp;amp;amp;amp;quot;);\n\tprintStudentList(list);\n\n    }\n\n    public static void createStudent() {\n\n\tStudent student = new Student();\n\tstudent.setStudentName(&amp;amp;amp;amp;amp;quot;Mayur&amp;amp;amp;amp;amp;quot;);\n\tstudent.setMarks(82);\n\tInteger rollNo = studentDao.insertStudent(student);\n\tlog.info(&amp;amp;amp;amp;amp;quot;insert Student Details: &amp;amp;amp;amp;amp;quot; + rollNo);\n\n    }\n\n    public static void updateStudent() {\n\n\tStudent student = new Student();\n\tstudent.setRollNo(1);\n\tInteger result = studentDao.updateStudentDetails(student);\n\tlog.info(&amp;amp;amp;amp;amp;quot;update Student Details: &amp;amp;amp;amp;amp;quot; + result);\n    }\n\n    public static void deleteStudent() {\n\n\tInteger rollNo = studentDao.deleteStudentFromDB(3);\n\tlog.info(&amp;amp;amp;amp;amp;quot;delete Student&amp;amp;#039;s rollNo: &amp;amp;amp;amp;amp;quot; + rollNo);\n\n    }\n\n    private static void printStudentList(ArrayList&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;?&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt; studentList) {\n\tfor (int i = 0; i &amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt; studentList.size(); i++) {\n\t    log.info(studentList.get(i).toString());\n\t}\n    }\n\n    public static void main(String arg[]) {\n\ttry {\n\t    setUp();\n\t    \/\/ updateStudent();\n\t    \/\/ createStudent();\n\t    \/\/ deleteStudent();\n\t    getAllStudents();\n\t} catch (Exception e) {\n\t    e.printStackTrace();\n\t}\n    }\n}\n\n[\/java]<\/pre>\n\n<p>Now our MyBatisDemo Application is ready to built and deploy.<\/p>\n<\/li>\n<li>\n<p><strong> Compilation and Run:<\/strong><\/p>\n<p>Now right click on \u201cTestStudentDAO\u201d class and click on \u201cRun as\u201d than click on \u201cJava Appilcation\u201d then our application run successfully and i am using apache log4j to do all the the loggings.<\/p>\n<p>This is what happen on my java console,<\/p>\n<pre>INFO [main] (TestStudentDAO.java:26) - Mybatis setup is in progress...\nINFO [main] (TestStudentDAO.java:31) - Connection Established Successfully.\nINFO [main] (TestStudentDAO.java:40) - Student List:\nINFO [main] (TestStudentDAO.java:78) - [Status] (1) John P Marks : 82\nINFO [main] (TestStudentDAO.java:78) - [Status] (2) Abdul K Marks : 94\nINFO [main] (TestStudentDAO.java:78) - [Status] (3) Raju S Marks : 35<\/pre>\n<\/li>\n<\/ul>\n<h2><b>Technical pros of MyBatis:<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Here are few pros of using MyBatis:<\/span>\n<\/p><ul><li><span style=\"font-weight: 400;\">  Supports Stored procedures.<\/span><\/li><li><span style=\"font-weight: 400;\">  Supports Inline SQL.<\/span><\/li><li><span style=\"font-weight: 400;\">  Supports Dynamic SQL.<\/span><\/li><li><span style=\"font-weight: 400;\"> Supports O\/RM.<\/span><\/li><\/ul>\n<h2><b>Summary of MyBatis:<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">MyBatis eliminates almost all of the JDBC code and manual setting of parameters and retrieval of results.It is a easiest way to build better database oriented application more quickly, efficiently with less code.<\/span><\/p>\n<h2><b>References for Blog:<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">1. http:\/\/www.mybatis.org\/core\/<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><strong>Download the Sample Project:<\/strong><a href=\"http:\/\/https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2012\/09\/MyBatisDemo.zip\">Here<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is MyBatis? MyBatis is a Higher version of iBatis. Its lightweight persistence framework which is mapping SQL databases and objects in Java, .NET, and Ruby on Rails. MyBatis support for custom SQL, Views, advanced mappings, stored procedures and declarative data caching.It is the new version of the iBatis Data Mapper Java Framework, which allows [&hellip;]<\/p>\n","protected":false},"author":31,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_s2mail":"","footnotes":""},"categories":[182],"tags":[236,238,234,237,235],"class_list":["post-1793","post","type-post","status-publish","format-standard","hentry","category-web-programming","tag-configuration-xml","tag-mybatis-design-aspects","tag-technical-pros-of-mybatis","tag-why-mybatis","tag-xml-mapper-file"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Configuring MyBatis 3 With MySQL In Java Projects - Mobisoft Infotech<\/title>\n<meta name=\"description\" content=\"Know more everything you need to know about MyBatis. What is it? Why is it used? Learn how to use with a sample database. Read more about this SQL Mapping Framework for Java, .NET and Ruby on Rails.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/mobisoftinfotech.com\/resources\/blog\/web-programming\/blog-on-mybatis\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Configuring MyBatis 3 With MySQL In Java Projects - Mobisoft Infotech\" \/>\n<meta property=\"og:description\" content=\"Know more everything you need to know about MyBatis. What is it? Why is it used? Learn how to use with a sample database. Read more about this SQL Mapping Framework for Java, .NET and Ruby on Rails.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/mobisoftinfotech.com\/resources\/blog\/web-programming\/blog-on-mybatis\" \/>\n<meta property=\"og:site_name\" content=\"Mobisoft Infotech\" \/>\n<meta property=\"article:published_time\" content=\"2012-09-18T12:53:14+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-18T10:26:49+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2012\/09\/packageStructure-e1347968283638.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t<meta property=\"og:image:height\" content=\"1024\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"swapnil.jagtap\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"swapnil.jagtap\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/web-programming\/blog-on-mybatis#article\",\"isPartOf\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/web-programming\/blog-on-mybatis\"},\"author\":{\"name\":\"swapnil.jagtap\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/#\/schema\/person\/cede7872e9104d5683178106162ed81a\"},\"headline\":\"Configuring MyBatis 3 With MySQL In Java Projects\",\"datePublished\":\"2012-09-18T12:53:14+00:00\",\"dateModified\":\"2024-11-18T10:26:49+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/web-programming\/blog-on-mybatis\"},\"wordCount\":462,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/web-programming\/blog-on-mybatis#primaryimage\"},\"thumbnailUrl\":\"http:\/\/https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2012\/09\/packageStructure-e1347968283638-1024x819.png\",\"keywords\":[\"Configuration XML\",\"MyBatis Design Aspects\",\"Technical pros of MyBatis\",\"Why MyBatis?\",\"XML Mapper File\"],\"articleSection\":[\"Web Programming\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/mobisoftinfotech.com\/resources\/blog\/web-programming\/blog-on-mybatis#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/web-programming\/blog-on-mybatis\",\"url\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/web-programming\/blog-on-mybatis\",\"name\":\"Configuring MyBatis 3 With MySQL In Java Projects - Mobisoft Infotech\",\"isPartOf\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/web-programming\/blog-on-mybatis#primaryimage\"},\"image\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/web-programming\/blog-on-mybatis#primaryimage\"},\"thumbnailUrl\":\"http:\/\/https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2012\/09\/packageStructure-e1347968283638-1024x819.png\",\"datePublished\":\"2012-09-18T12:53:14+00:00\",\"dateModified\":\"2024-11-18T10:26:49+00:00\",\"author\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/#\/schema\/person\/cede7872e9104d5683178106162ed81a\"},\"description\":\"Know more everything you need to know about MyBatis. What is it? Why is it used? Learn how to use with a sample database. Read more about this SQL Mapping Framework for Java, .NET and Ruby on Rails.\",\"breadcrumb\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/web-programming\/blog-on-mybatis#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/mobisoftinfotech.com\/resources\/blog\/web-programming\/blog-on-mybatis\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/web-programming\/blog-on-mybatis#primaryimage\",\"url\":\"http:\/\/https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2012\/09\/packageStructure-e1347968283638-1024x819.png\",\"contentUrl\":\"http:\/\/https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2012\/09\/packageStructure-e1347968283638-1024x819.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/web-programming\/blog-on-mybatis#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/mobisoftinfotech.com\/resources\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Configuring MyBatis 3 With MySQL In Java Projects\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/#website\",\"url\":\"https:\/\/mobisoftinfotech.com\/resources\/\",\"name\":\"Mobisoft Infotech\",\"description\":\"Discover Mobility\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/mobisoftinfotech.com\/resources\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/#\/schema\/person\/cede7872e9104d5683178106162ed81a\",\"name\":\"swapnil.jagtap\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/202d98c3b583f277cb629d47829dac84f9973d7f489d8d727fadf7184dabe8b4?s=96&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/202d98c3b583f277cb629d47829dac84f9973d7f489d8d727fadf7184dabe8b4?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/202d98c3b583f277cb629d47829dac84f9973d7f489d8d727fadf7184dabe8b4?s=96&r=g\",\"caption\":\"swapnil.jagtap\"},\"sameAs\":[\"http:\/\/www.mobisoftinfotech.com\/\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Configuring MyBatis 3 With MySQL In Java Projects - Mobisoft Infotech","description":"Know more everything you need to know about MyBatis. What is it? Why is it used? Learn how to use with a sample database. Read more about this SQL Mapping Framework for Java, .NET and Ruby on Rails.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/mobisoftinfotech.com\/resources\/blog\/web-programming\/blog-on-mybatis","og_locale":"en_US","og_type":"article","og_title":"Configuring MyBatis 3 With MySQL In Java Projects - Mobisoft Infotech","og_description":"Know more everything you need to know about MyBatis. What is it? Why is it used? Learn how to use with a sample database. Read more about this SQL Mapping Framework for Java, .NET and Ruby on Rails.","og_url":"https:\/\/mobisoftinfotech.com\/resources\/blog\/web-programming\/blog-on-mybatis","og_site_name":"Mobisoft Infotech","article_published_time":"2012-09-18T12:53:14+00:00","article_modified_time":"2024-11-18T10:26:49+00:00","og_image":[{"width":1280,"height":1024,"url":"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2012\/09\/packageStructure-e1347968283638.png","type":"image\/png"}],"author":"swapnil.jagtap","twitter_card":"summary_large_image","twitter_misc":{"Written by":"swapnil.jagtap","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/web-programming\/blog-on-mybatis#article","isPartOf":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/web-programming\/blog-on-mybatis"},"author":{"name":"swapnil.jagtap","@id":"https:\/\/mobisoftinfotech.com\/resources\/#\/schema\/person\/cede7872e9104d5683178106162ed81a"},"headline":"Configuring MyBatis 3 With MySQL In Java Projects","datePublished":"2012-09-18T12:53:14+00:00","dateModified":"2024-11-18T10:26:49+00:00","mainEntityOfPage":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/web-programming\/blog-on-mybatis"},"wordCount":462,"commentCount":0,"image":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/web-programming\/blog-on-mybatis#primaryimage"},"thumbnailUrl":"http:\/\/https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2012\/09\/packageStructure-e1347968283638-1024x819.png","keywords":["Configuration XML","MyBatis Design Aspects","Technical pros of MyBatis","Why MyBatis?","XML Mapper File"],"articleSection":["Web Programming"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/mobisoftinfotech.com\/resources\/blog\/web-programming\/blog-on-mybatis#respond"]}]},{"@type":"WebPage","@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/web-programming\/blog-on-mybatis","url":"https:\/\/mobisoftinfotech.com\/resources\/blog\/web-programming\/blog-on-mybatis","name":"Configuring MyBatis 3 With MySQL In Java Projects - Mobisoft Infotech","isPartOf":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/#website"},"primaryImageOfPage":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/web-programming\/blog-on-mybatis#primaryimage"},"image":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/web-programming\/blog-on-mybatis#primaryimage"},"thumbnailUrl":"http:\/\/https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2012\/09\/packageStructure-e1347968283638-1024x819.png","datePublished":"2012-09-18T12:53:14+00:00","dateModified":"2024-11-18T10:26:49+00:00","author":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/#\/schema\/person\/cede7872e9104d5683178106162ed81a"},"description":"Know more everything you need to know about MyBatis. What is it? Why is it used? Learn how to use with a sample database. Read more about this SQL Mapping Framework for Java, .NET and Ruby on Rails.","breadcrumb":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/web-programming\/blog-on-mybatis#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/mobisoftinfotech.com\/resources\/blog\/web-programming\/blog-on-mybatis"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/web-programming\/blog-on-mybatis#primaryimage","url":"http:\/\/https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2012\/09\/packageStructure-e1347968283638-1024x819.png","contentUrl":"http:\/\/https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2012\/09\/packageStructure-e1347968283638-1024x819.png"},{"@type":"BreadcrumbList","@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/web-programming\/blog-on-mybatis#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/mobisoftinfotech.com\/resources\/"},{"@type":"ListItem","position":2,"name":"Configuring MyBatis 3 With MySQL In Java Projects"}]},{"@type":"WebSite","@id":"https:\/\/mobisoftinfotech.com\/resources\/#website","url":"https:\/\/mobisoftinfotech.com\/resources\/","name":"Mobisoft Infotech","description":"Discover Mobility","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/mobisoftinfotech.com\/resources\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/mobisoftinfotech.com\/resources\/#\/schema\/person\/cede7872e9104d5683178106162ed81a","name":"swapnil.jagtap","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/202d98c3b583f277cb629d47829dac84f9973d7f489d8d727fadf7184dabe8b4?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/202d98c3b583f277cb629d47829dac84f9973d7f489d8d727fadf7184dabe8b4?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/202d98c3b583f277cb629d47829dac84f9973d7f489d8d727fadf7184dabe8b4?s=96&r=g","caption":"swapnil.jagtap"},"sameAs":["http:\/\/www.mobisoftinfotech.com\/"]}]}},"_links":{"self":[{"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/posts\/1793","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/users\/31"}],"replies":[{"embeddable":true,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/comments?post=1793"}],"version-history":[{"count":193,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/posts\/1793\/revisions"}],"predecessor-version":[{"id":32177,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/posts\/1793\/revisions\/32177"}],"wp:attachment":[{"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/media?parent=1793"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/categories?post=1793"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/tags?post=1793"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}