kotlin中如何上传数组到mysql数据库

问题描述 投票:0回答:0

如何使用库“mysql:mysql-connector-java:5.1.25”在 Kotlin(android) 中插入 MySQL 数据库

目前,我只能组织这种类型的请求,但应用程序会处理它们很长时间

包含有关数组结构及其声明的数据的文件:

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

我的查询:

 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() 
           }
android database kotlin mysql-connector kotlin-multiplatform
© www.soinside.com 2019 - 2024. All rights reserved.