import java.sql.Connection
import java.sql.DriverManager
object ScalaJDBC {
def main(args: Array[String]) {
// connect to the database named "mysql" on the localhost
val driver = "com.mysql.jdbc.Driver"
val url = "jdbc:mysql://localhost/test"
val username = "root"
val password = "123abc"
var connection:Connection = null
try {
Class.forName(driver)
connection = DriverManager.getConnection(url, username, password)
val statement = connection.createStatement()
val resultSet = statement.executeQuery("select * from test.nbiottable;")
while ( resultSet.next() ) {
val name = resultSet.getString("NBID")
val password = resultSet.getString("loraid")
println( name + ", " + password)
}
} catch {
case e => e.printStackTrace
}
connection.close()
}
}