简体   繁体   English

从Java调用postgresql函数

[英]postgresql function call from java

I have very strange issue. 我有一个很奇怪的问题。 I design one function which is inserting values into postgresql table. 我设计了一个将值插入到postgresql表中的函数。 But when I try to call that function from java at that time it seems like did not insert. 但是,当我尝试在那时从Java调用该函数时,似乎没有插入。 Even I am not getting error as well. 即使我也没有得到错误。 My code is below. 我的代码如下。

String query = "{call postgres.addToLog(?,?,?,?,?,?,?)}";

    try{

        CallableStatement ps = getPostgresConfiguratoin().prepareCall(query);

        ps.setTimestamp(1, new Timestamp(new java.util.Date().getTime()));
        ps.setInt(2, 705);
        ps.setInt(3, 1);
        ps.setInt(4, 1);
        ps.setString(5, "192.168.2.101");
        ps.setString(6, null);
        ps.setString(7, query);
        ps.executeUpdate();
        ps.close();
    }catch(Exception ex){

    }

Is there anything wrong with my call? 我的电话有什么问题吗?

I found in logs that my function insert query has one column name which has wrong spelling so my insert query never insert anything. 我在日志中发现函数插入查询具有一列名称,该列名称的拼写错误,因此我的插入查询从不插入任何内容。 After furthermore research I found out that as best practice to provide exception handling into PL-SQL as well. 经过进一步的研究,我发现这也是向PL-SQL提供异常处理的最佳实践。 I provide Exception handler into my PL-SQL block and it return error which I can see on my Java program side as well. 我在我的PL-SQL块中提供了异常处理程序,并且它返回错误,我也可以在Java程序端看到该错误。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM