1、Scala连接mysql数据库:
import java.sql.{Connection, DriverManager, PreparedStatement, ResultSet}
object mysqlConn {
def main(args: Array[String]): Unit = {
Class.forName("com.mysql.jdbc.Driver")
val conn: Connection = DriverManager.getConnection("jdbc:mysql://bash/User?useUnicode=true&characterEncoding=utf8&useSSL=false", "root", "123456")
println(conn)
val statement: PreparedStatement = conn.prepareStatement("select * from stuInfo")
val result: ResultSet = statement.executeQuery()
while (result.next()){
val number: String = result.getString("stuNumber")
val name: String = result.getString("stuName")
val password: String = result.getString("password")
println(s"学号:${number},姓名:${name},密码:${password}")
}
}
}
2、Scala连接redis数据库:
import redis.clients.jedis.Jedis
object redisConn {
def main(args: Array[String]): Unit = {
//之前创建过redis集群,所以启动集群的里面的redis配置文件,就要启动整个集群
//启动单独的redis就要关闭集群设置就行
val jedis = new Jedis("master", 7000)
jedis.set("name","少帅")
val name: String = jedis.get("name")
println(name)
}
}
标签:name,val,Scala,redis,result,mysql,String
From: https://blog.csdn.net/ABU009/article/details/142833225