package com
import java.sql.{Connection, DriverManager}
object JDBCTest {
//感觉跟java没有太大的区别!
def main(args: Array[String]) {
val url = "jdbc:mysql://localhost/newshow?user=root&password=root"
var connection: Connection = null
classOf[com.mysql.jdbc.Driver] //加载数据库驱动
connection = DriverManager.getConnection(url)//获取数据库连接
try {
val statement = connection.createStatement()
val resultSet = statement.executeQuery("select * from customer")
while (resultSet.next()) {
val id = resultSet.getString("id")
val name = resultSet.getString("name")
val lon = resultSet.getString("lon");
val lat = resultSet.getString("lat");
println("地址 = " + name + ",经度 " + lon + ",纬度 " + lat)
}
} catch {
case e => e.printStackTrace
}
connection.close()
}
}
scala连接mysql数据库
最新推荐文章于 2024-05-15 14:07:02 发布