PostgreSQL& JDBC:使用RETURNING INSERT INTO返回空结果集

时间:2014-08-31 12:37:08

标签: java sql postgresql jdbc insert-into

我有一个带有返回值的insert语句。问题是,只有INSERT INTO部分可以工作,但什么都不返回。我也试过了表属性和常量值。我正在使用 org.postgresql:postgresql:9.3-1101-jdbc41 驱动程序。

是否有任何解决方案可以使此查询正常工作?

private Blitz blitzToDB(Blitz curr)
{
    try
    {
        SolarPosition position = new SolarPosition(System.currentTimeMillis(),curr.BlitzLat,curr.BlitzLon);
        PreparedStatement blitz_insertion = mPostgresConn.prepareCall("INSERT INTO blitzv2_blitzes (blitz_lat, blitz_lon, blitz_mapx, blitz_mapy, blitz_map, blitz_country, blitz_region, blitz_subregion, blitz_settlem, blitz_settlemtype, blitz_concattype, blitz_sunelev, blitz_str) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?) RETURNING '0'");
        blitz_insertion.setDouble(1, curr.BlitzLat);
        blitz_insertion.setDouble(2, curr.BlitzLon);
        blitz_insertion.setDouble(3,0);
        blitz_insertion.setDouble(4, 0);
        blitz_insertion.setString(5, "LIVE");
        blitz_insertion.setString(6,curr.BlitzCountry);
        blitz_insertion.setString(7,curr.BlitzRegion);
        blitz_insertion.setString(8,curr.BlitzSubregion);
        blitz_insertion.setString(9,curr.BlitzSettlem);
        blitz_insertion.setString(10,curr.BlitzSettlemType);
        blitz_insertion.setString(11,"NONE");
        blitz_insertion.setDouble(12,curr.SunElevation);
        blitz_insertion.setString(13,curr.BlitzStreet);
        ResultSet rs = blitz_insertion.executeQuery();
        if(rs.next())
        {
            System.out.println(rs.getInt(1));
           // curr.BlitzID = rs.getLong(1);
        }
        else
        {
            System.out.println(":(");
        }
        return curr;
    }
    catch (Exception ex)
    {
        ex.printStackTrace();
        ErrorLog.pushError(ErrorLog.ErrorKinds.BlitzSqlError,ex);
        curr.BlitzID = 0L;
        return curr;
    }

}

0 个答案:

没有答案