MYBATIS - Environment



You would have to set up a proper environment for MyBatis before starting off with the actual development work. This chapter explains how to set up a working environment for MyBatis.

MyBatis Installation

Carry out the following simple steps to install MyBatis on your machine −

  • Download the latest version of MyBatis from Download MYBATIS.

  • Download the latest version of mysqlconnector from Download MySQL Connector.

  • Unzip the downloaded files to extract .jar files and keep them in appropriate folders/directory.

  • Set CLASSPATH variable for the extracted .jar files appropriately.

Database Setup

Create an EMPLOYEE table in any MySQL database using the following syntax −

mysql> DROP TABLE IF EXISTS details.student;
CREATE TABLE  details.student(
   ID int(10) NOT NULL AUTO_INCREMENT,  
   NAME varchar(100) NOT NULL,
   BRANCH varchar(255) NOT NULL,
   PERCENTAGE int(3) NOT NULL,  
   PHONE int(10) NOT NULL,
   EMAIL varchar(255) NOT NULL,
   PRIMARY KEY ( ID )
);

MyBatis Eclipse Setup

If you want to develop MyBatis Application using eclipse, carry out the following steps −

MyBatis eclipse setup steps
<project xmlns = "http://maven.apache.org/POM/4.0.0" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

   <modelVersion>4.0.0</modelVersion>
   <groupId>mybatisfinalexamples</groupId>
   <artifactId>mybatisfinalexamples</artifactId>
   <version>0.0.1-SNAPSHOT</version>
  
   <build>
      <sourceDirectory>src</sourceDirectory>
		
      <plugins>
         <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
               <source>1.8</source>
               <target>1.8</target>
            </configuration>
         </plugin>
      </plugins>
		
   </build>
  
   <dependencies>
	
      <dependency>
         <groupId>org.mybatis</groupId>
         <artifactId>mybatis</artifactId>
         <version>3.3.0</version>
      </dependency>	
	 
      <dependency>
         <groupId>mysql</groupId>
         <artifactId>mysql-connector-java</artifactId>
         <version>5.1.6</version>
      </dependency>
		
   </dependencies>  
	
</project>
Advertisements