From: | Matthew Chambers <mchambers(at)wetafx(dot)co(dot)nz> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Spring JDBC and the PostgreSQL JDBC driver |
Date: | 2014-04-03 21:48:25 |
Message-ID: | 533DD729.5090509@wetafx.co.nz |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 04/04/14 10:22, John R Pierce wrote:
> On 4/3/2014 1:31 PM, Matthew Chambers wrote:
>> This removes all the boilerplate associated with old style JDBC. It
>> also means you get great reuse of your SQL code since the transaction
>> starts at the entry point. Most of my SQL related code is just 1
>> liners using Springs JdbcTemplate class. I've written some massive
>> applications with this style. My current postgres project sees about
>> 4gbps of traffic during peak times and there is not an explicit
>> begin/commit in the entire code base.
>
> so how does the OP use Jdbc4Array.getArray() on an object returned
> from a Spring execute if Spring has automagically released/closed the
> connection?
>
>
>
Well, you wouldn't be calling Jdbc4Array.getArray() anywhere in your
code where you don't have a connection, you would be doing that where
the connection is active. The connection doesn't go away until the
function that checked the connection out returns. Assuming you have a
ResultSet object you can do this:
String[] arrayOfStrings= (String[])
resultSet.getArray("col_name").getArray();
To put data into an array field, you have to use a
PreparedStatementCreator which gives you access to the
java.sql.Connection, so you can call "createArrayOf" from that.
jdbc.update(new PreparedStatementCreator() {
public PreparedStatement createPreparedStatement(final
Connection conn) throws SQLException {
final PreparedStatement ret =
conn.prepareStatement(UPDATE_TAGS);
ret.setObject(1, conn.createArrayOf("text", tags));
ret.setObject(2, id);
return ret;
}
});
From | Date | Subject | |
---|---|---|---|
Next Message | Scott Marlowe | 2014-04-03 22:19:45 | Re: SSD Drives |
Previous Message | Steven Schlansker | 2014-04-03 21:48:03 | Re: Is it safe to stop postgres in between pg_start_backup and pg_stop_backup? |