如何使用库“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()
}