普通数据写入mysql

val url = "jdbc:mysql://地址/库名?characterEncoding=utf8"
val username = "user"
val password = "password"

classOf[com.mysql.jdbc.Driver]

def getConnection(): sql.Connection = {
  DriverManager.getConnection(url, username, password)
}

val conn = this.getConnection()
try{
  val sql = new StringBuilder()
 .append("INSER TINTO 表名(doc_id,client_name,call_center,address,latitude,longitude,city_id,area_id,month_sale_num,shipping_time,geo_hash,create_time,update_time)")
    .append("     VALUES(?,?,?)")
  val pstm = conn.prepareStatement(sql.toString())
  pstm.setInt(1, doc_id)
  pstm.setString(2, client_name)
  pstm.setString(3, call_center)

  pstm.executeUpdate() > 0
}
finally {
  conn.close()
}

猜你喜欢

转载自blog.csdn.net/tang_xiaotang/article/details/80967013