0

How to make an INSERT into a MySQL database in Kotlin(android) using the library "mysql:mysql-connector-java:5.1.25"

At the moment, I was able to organize only this type of requests, but they are processed by the application for a very long time

File with data about the structure of the array and its declaration:

data class StudentsData(
    val id: Int,
    val group: String,
    val fullName: String,
)
val studData: MutableList<StudentsData> = mutableListOf()

My query:

 for (index in studData.indices) {
               val value = studData[index]
               thread {
                   try {
                       Class.forName("com.mysql.jdbc.Driver")
                       val connection = DriverManager.getConnection(url, user, pass)
                       val insert ="INSERT INTO students (id, uid, studGroup, fullName) VALUES " +
                               "(NULL, '${uid}','${value.group}','${value.fullName}');"
                       val queryInsertAccount = connection.prepareStatement(insert)
                       queryInsertAccount.execute()
                   }
                   catch (e: Exception) {
                       Log.e("error", "${e.message}")
                   }
               }.join() 
           }
Phil Dukhov
  • 67,741
  • 15
  • 184
  • 220
DenisAlal
  • 1
  • 1
  • 1
    Please [reconsider your use of JDBC on Android](https://stackoverflow.com/questions/15853367/jdbc-vs-web-service-for-android) – CommonsWare Feb 19 '23 at 12:18

0 Answers0