我正在尝试使用Scala将记录插入Oracle数据库并获取错误
db1.scala:18:错误:值提交不是java.sql.Statement的成员 statement.commit()
object ScalaJdbcConnectSelect {
def main(args: Array[String]) {
val driver = "oracle.jdbc.driver.OracleDriver"
val url = "jdbc:oracle:thin:@cdtsdcpt-scan.rxcorp.com:1521/DDCPAD00.WORLD"
val username = "DCA_DATA"
val password = "DCA_DATA"
var connection:Connection = null
try {
Class.forName(driver)
connection = DriverManager.getConnection(url, username, password)
// create the statement, and run the select query
val statement = connection.createStatement()
// val resultSet = statement.executeQuery("SELECT org_short_nm FROM dc_org")
val sql_st="INSERT INTO DCP_ITALY_STG" + " VALUES ('20411384','71771622','4378038','257.550','15.000')"
statement.executeUpdate(sql_st)
println("Inserted records into the table...")
val resultSet = statement.executeQuery("SELECT num FROM DCP_ITALY_STG")
connection.commit()
println("Hello india")
while ( resultSet.next() )
{
val host = resultSet.getString("num")
println(host)
println("Hello india")
}
} catch {
case e: Throwable => e.printStackTrace
}
connection.close()
}
}}
}
答案 0 :(得分:1)
应该是
connection.commit()
而不是
statement.commit()
Docs说:
Connection#commit()
- 自上次提交/回滚以来所做的所有更改都是永久性的 并释放此Connection当前持有的所有数据库锁 对象