Reputation: 25
Can I connect an Android app to MySQL database in my computer? Just tell me the way or a library name and let me google it to learn about.
Upvotes: 1
Views: 3782
Reputation: 28
MySQL connector for java works for Kotlin as well. You can download it from https://dev.mysql.com/downloads
And then you can kotlint like that:
val connectionProps = Properties()
connectionProps.put("user", username)
connectionProps.put("password", password)
try {
Class.forName("com.mysql.jdbc.Driver").newInstance()
conn = DriverManager.getConnection(“url”, connectionProps)
} catch (ex: SQLException) {
// handle any errors
ex.printStackTrace()
} catch (ex: Exception) {
// handle any errors
ex.printStackTrace()
}
Upvotes: 1