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;
}
});
--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general