简体   繁体   English

我无法使用 scala 将记录插入到 oracle 数据库中

[英]I'm not able to insert record into oracle database using scala

I'm trying to insert records into Oracle database using Scala and getting error我正在尝试使用 Scala 将记录插入 Oracle 数据库并出现错误

db1.scala:18: error: value commit is not a member of java.sql.Statement statement.commit() 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()

        }
        }}
}

It should be它应该是

connection.commit()

instead of代替

statement.commit()

Docs says: 文档说:

Connection#commit() - Makes all changes made since the previous commit/rollback permanent and releases any database locks currently held by this Connection object. Connection#commit() - 使自上次提交/回滚以来所做的所有更改永久化,并释放当前由该 Connection 对象持有的所有数据库锁。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我无法将记录插入到在oracle数据库中创建的表中。 我在做什么错? - I am unable to insert a record into my table created in oracle database. What mistake am I doing? 我正在尝试使用Java更新oracle数据库中的密码。 难道我做错了什么? - I'm trying to update my password in oracle database using Java. Am I doing something wrong? 使用jdbc在oracle数据库中插入当前日期 - insert current date in oracle database using jdbc 使用XML字符串插入Oracle数据库 - Using an XML String to Insert into Oracle Database 使用Java在Oracle中插入一个日期为jDateChooser且日期为null的记录 - Insert a record with a date from a jDateChooser and a null for a number in Oracle using Java 如何测试使用Junit在数据库中插入记录的void方法? - how can I test a void method that insert a record in database using Junit? Android Studio [JDBC]:为什么我无法访问数据库 - Android Studio [JDBC]: Why I'm not able to reach the database 无法插入到 SQLite 数据库 - Not able to INSERT to SQLite database 使用群集类型主机时无法连接 oracle 数据库 - Not able to connect oracle Database while using Cluster type HOST 我在我的 Spring 引导项目中使用 h2 DB。 我能够连接到 h2 控制台,但没有创建数据库 - I'm using h2 DB in my Spring Boot project. I'm able to connect to h2 consle, but database is not getting created
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM