Question about using Queryband in a macro called from a JAVA program

General
Enthusiast

Question about using Queryband in a macro called from a JAVA program

We are in the process of moving most of our applications use Querybanding and one of the ways we are doing this is by implementing the queryband as part of a macro this way we can ensure the query band is used.  I can successfully run this macro via programs like Squirrel SQL, Teradata Studio Express/Teradata Studio, and a few other java based programs.  However if the developer trying to write the code can successfully call a macro that doesn't contain the queryband, but it fails when he tries to execute the macro with query band in it.  I have looked at a few of the Java examples that discuss macros with multiple statements that return no results and those that return results, I figure it is some combination of those, but i'm not sure how the code should look to handle the queryband since it is the first statement and doesn't return a result but the 2nd statement does, so we want to get the second result.  I'm not a Java programmer so not sure what the right approach would be.   

Does anyone have a code snippet that they would be willing to share that would address that issue?

Thanks

2 REPLIES
Enthusiast

Re: Question about using Queryband in a macro called from a JAVA program

after hacking around with the example code, I was able to figure out the issue.  The set query_band doesn't actually return any thing to resultset.  we were checking for something when we should have been checking for null with the first resultset and then move to the next resultset.

this is what the crude code looked like

boolean firstResult = stmt.execute(sMacroExec);
ResultSet rs = stmt.getResultSet();

if (rs == null)
{
System.out.println("The first resultset is null");
if (stmt.getMoreResults() == false)
{
throw new IllegalStateException("Bad Result");
}
rs = stmt.getResultSet();
while (rs.next())
{
System.out.println(rs.getString(1));
}
}

Re: Question about using Queryband in a macro called from a JAVA program

The code looks very nice, helped me out with some problems I had, thank you very much dude! :)