昨天往postgre中插入数据的时候,数据库中字段写有大写字母,代码中也跟库中字段一致。运行的时候报错,说是识别不了字段。把库中还有代码中统一换成小写就好了。!!!
def saveTrip(tripid: String, point: Trip, tableName: String): Unit = {
val conn = pool.borrowObject()
var sql = ""
//TODO tb_trip_ecar${tableName}
sql = s"insert into tb_trip_ecar${tableName}(tid, terminal, wayid, fp, tp, dir, utc) values('$tripid','${point.uuid}', ${point.wayid}, ${point.fp}, ${point.tp},${point.dir},${point.utc})"
conn.executeUpdate(sql)
pool.returnObject(conn)
}
注意: string类型的字段插入postgre数据库时 记得带 ' ' 号!
sql = s"insert into tb_trip_ecar${tableName}(tid, terminal, wayid, fp, tp, dir, utc) values(
'$tripid',
'${point.uuid}', ${point.wayid}, ${point.fp}, ${point.tp},${point.dir},${point.utc})"