如何在Kotlin API中调用存储过程?

时间:2019-04-16 06:02:12

标签: oracle stored-procedures kotlin

我们正在Kotlin中转换Java Spring Boot微服务。在Java Spring Boot中,我们在API中具有Oracle存储过程传递参数和接受响应参数。在Kotlin中进行转换时,我们只能在Kotlin中调用Oracle存储过程。请找到我们尝试调用存储过程的代码。请参阅注释行代码,该代码行不通,Kotlin代码示例中没有任何内容。

package com.manoj.common

import org.springframework.web.bind.annotation.RestController
import java.util.concurrent.atomic.AtomicLong
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.context.annotation.ComponentScan
import java.sql.Connection
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.jdbc.core.JdbcTemplate
import java.sql.CallableStatement
import javax.sql.DataSource
import oracle.jdbc.OracleTypes
import java.sql.Statement
import java.sql.PreparedStatement
import java.sql.ResultSet

@RestController

class GreetingController 
{

  val counter = AtomicLong()
  @Autowired
  lateinit var datasource: DataSource;
  @GetMapping("/CallProcedure")

  fun greeting(@RequestParam(value = "name", defaultValue = "World") name: String) 
   { 
     print("Welcome Chetan")
    try {
          val conn: Connection = datasource.getConnection();
          print("Connection :  " + conn)
          var callableStatement: CallableStatement = conn.prepareCall("{call Get_Sell_Txn_Status(?,?,?,?,?)}")

    //callableStatement.setString(1, "8917102");
    //callableStatement.setString(2, "8917");
    //callableStatement.setString(3, "bbd30d20-028d-47ea-98c6-2554e869f1af:8917");
    //callableStatement.registerOutParameter(4, OracleTypes.CURSOR);
    //callableStatement.registerOutParameter(5, OracleTypes.CURSOR);
    //callableStatement.executeUpdate();
    //var resultSet ResultSet = as ResultSet callableStatement.getObject(4)
    var preparedStatement: PreparedStatement? = null
    preparedStatement = conn.prepareStatement("select * from KOSHTAKRUTI_LOGIN")    
    val rs: ResultSet = preparedStatement.executeQuery()

    while (rs.next()) 
     {
            println(rs.getString(3)+" "+rs.getString(4))
         }

        print("You are here")
      } 
       catch (e: Exception) {}
   } 
}

如何从Kotlin调用存储过程?

0 个答案:

没有答案