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()
}