001/* 002 * Copyright (c) 2004-2013 Tada AB and other contributors, as listed below. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the The BSD 3-Clause License 006 * which accompanies this distribution, and is available at 007 * http://opensource.org/licenses/BSD-3-Clause 008 * 009 * Contributors: 010 * Tada AB 011 */ 012package org.postgresql.pljava.example; 013 014import java.sql.DriverManager; 015import java.sql.PreparedStatement; 016import java.sql.ResultSet; 017import java.sql.SQLException; 018 019import org.postgresql.pljava.ResultSetHandle; 020 021/** 022 * This implementation uses another function that returns a set of a complex 023 * type and returns the ResultSet produced by a query. 024 * 025 * @author Thomas Hallgren 026 */ 027public class UsingPropertiesAsResultSet implements ResultSetHandle { 028 public static ResultSetHandle getProperties() throws SQLException { 029 return new UsingPropertiesAsResultSet(); 030 } 031 032 private PreparedStatement m_statement; 033 034 @Override 035 public void close() throws SQLException { 036 m_statement.close(); 037 m_statement = null; 038 } 039 040 @Override 041 public ResultSet getResultSet() throws SQLException { 042 m_statement = DriverManager.getConnection("jdbc:default:connection") 043 .prepareStatement("SELECT * FROM propertyExample()"); 044 return m_statement.executeQuery(); 045 } 046}