How to connect to MySQL Database from Kotlin using JDBC

Kotlin Tutorial – We shall learn to connect to MySQL Database from Kotlin using JDBC with the help a Kotlin Example Program.

Following is a step by step process explained to connect to MySQL Database from Kotlin using JDBC :

  • Step 1 : Add MySQL connector for java

    MySQL connector for java works for Kotlin as well. Download MySQL connector for java, mysql-connector-java-5.1.42-bin.jar , from https://dev.mysql.com/downloads/connector/j/5.1.html. Open IntelliJ IDEA, Click on File in Menu, Click on Project Structure, Click on Libraries on the left panel, and add the jar to Libraries.

    Add MySQL jar to Kotlin Java Runtime Library - Connect to MySQL Database from Kotlin using JDBC - Kotlin Tutorial

    Add MySQL jar to Kotlin Java Runtime Library

  • Step 2 : Establish a connection to MySQL Server

  • Step 3 : Execute MySQL Query to show DATABASES available

Kotlin Example Program to connect to MySQL Database from Kotlin using JDBC

 

Conclusion :

In this Kotlin Tutorial, we have learnt to connect to MySQL Database from Kotlin using JDBC with the help of Kotlin Example Program.