Project in Java Skill Tree

MyBatis Database Integration Project

Beginner

In this project, you will learn how to use MyBatis, a popular Java persistence framework, to interact with a MySQL database. Specifically, you will learn how to use input parameters in SQL queries and retrieve course information based on the teacher's name.

Java

Introduction

In this project, you will learn how to use MyBatis, a popular Java persistence framework, to interact with a MySQL database. Specifically, you will learn how to use input parameters in SQL queries and retrieve course information based on the teacher's name.

👀 Preview

[labex] DEBUG [main] - Setting autocommit to false on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@642a7222]
[labex] DEBUG [main] - ==>  Preparing: SELECT * FROM course WHERE teacher LIKE CONCAT('%', ?, '%') ORDER BY cNo DESC
[labex] DEBUG [main] - ==> Parameters: Am(String)
[labex] DEBUG [main] - <==      Total: 2
Course Number: 3        Course Name: Python     Teacher: Liam
Course Number: 1        Course Name: HTML       Teacher: Amy

🎯 Tasks

In this project, you will learn:

  • Implement the CourseMapper interface to define a method for retrieving courses based on the teacher's name
  • Write the SQL query in the CourseMapper.xml file to perform a fuzzy search on the teacher column and sort the results in descending order by course number
  • Test the CourseMapper implementation in the MyBatisTest class to ensure the desired functionality

🏆 Achievements

After completing this project, you will be able to:

  • Use MyBatis to interact with a MySQL database
  • Pass input parameters to SQL queries using a Map
  • Perform a fuzzy search on a database column and sort the results
  • Test the functionality of a MyBatis mapper using a JUnit test case

Teacher

labby

Labby

Labby is the LabEx teacher.