import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Types;

/**
 * 
 */
public class TestDriver
{
	private static void testSomeInSomeOut() throws Exception
	{
		String url = "jdbc:postgresql://localhost/db";
		Connection con = DriverManager.getConnection(url, "user", "pwd");
		
		CallableStatement cstmt = con.prepareCall("{call test_somein_someout(?,?,?)}");
		cstmt.registerOutParameter(2, Types.VARCHAR);
	    cstmt.registerOutParameter(3, Types.BIGINT);
	    cstmt.setInt(1,20);
	    cstmt.executeQuery();
	    String out1 = cstmt.getString(1);
	    long out2 = cstmt.getLong(2);
	    System.out.println("out1=[" + out1 + "]  out2=" + out2);
	    cstmt.close();
	    con.close();
	}
	
	private static void testAllInOut() throws Exception
	{
		String url = "jdbc:postgresql://localhost/db";
		Connection con = DriverManager.getConnection(url, "user", "pwd");
		
		CallableStatement cstmt = con.prepareCall("{call test_allinout(?,?,?)}");
		cstmt.registerOutParameter(1, Types.INTEGER);
		cstmt.registerOutParameter(2, Types.VARCHAR);
	    cstmt.registerOutParameter(3, Types.BIGINT);
	    cstmt.setInt(1,20);
	    cstmt.setString(2,"hi");
	    cstmt.setLong(3,123);
	    cstmt.executeQuery();
	    int out1 = cstmt.getInt(1);
	    String out2 = cstmt.getString(2);
	    long out3 = cstmt.getLong(3);
	    System.out.println("out1=" + out1 + " out2=[" + out2 + "]  out3=" + out3);
	    cstmt.close();
	    con.close();
	}
	
	
	public static void main(String[] str) throws Exception
	{
		Class.forName("org.postgresql.Driver");
		try {
			testSomeInSomeOut();
		}
		catch (Exception e) {
			e.printStackTrace();
		}
		try {
			testAllInOut();
		}
		catch (Exception e) {
			e.printStackTrace();
		}
	}
}
