Hai Friends,
How to access multiple result sets in java? iam using getMoreResults, but iam able to access only half of data from second table... is there any way to access. please help me for this problem
Hai Friends,
How to access multiple result sets in java? iam using getMoreResults, but iam able to access only half of data from second table... is there any way to access. please help me for this problem
Hai Friends,
How to access multiple result sets in java? iam using getMoreResults, but iam able to access only half of data from second table... is there any way to access. please help me for this problem
you might want to post some code if you want us to take a look at it.
here is my code...
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package sampledb;
import javax.sql.*;
import java.sql.*;
/**
*
* @author venkateshwaran
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
try
{
int cnt=0;
Connection connection=null;
Statement statement=null;
String dbusernme="sa";
String dbpwd="proview";
String dbname="bgjava";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connection = DriverManager.getConnection("jdbc:odbc:bgjava", dbusernme, dbpwd);
statement =connection.createStatement();
ResultSet resultsetlt =statement.executeQuery("exec twotables");
ResultSetMetaData rs = resultsetlt.getMetaData();
int colcount = rs.getColumnCount();
cnt=0;
String strdet="";
do
{
strdet="";
while(resultsetlt.next())
{
cnt++;
for (int i=1;i<=colcount ;i++)
{
try
{
strdet=resultsetlt.getString(i)+",~,";
}
catch (Exception ex)
{
System.out.println("ex "+ex);
}
}
}
System.out.println("Result "+strdet);
/* boolean ac=statement.getMoreResults(1);
System.out.println(ac);*/
}
while(statement.getMoreResults());
// while(statement.getMoreResults(0));
}
catch(SQLException ex)
{
System.out.println("Exception "+ex);
}
catch(ClassNotFoundException exp)
{
System.out.println("Exception "+exp);
}
}
}
Three important lines for this kind of query:
1)
Do not get resulset from statement.executeQuery("exec twotables")
Instead use below method in Statement interface:
boolean execute(String sql) throws SQLException;
2)
Get result set using
ResultSet rs = statement.getResultSet();
3)
And yes, you are doing correct thing when using:
while(statement.getMoreResults());
Three important lines for this kind of query:
1)
Do not get resulset from statement.executeQuery("exec twotables")
Instead use below method in Statement interface:
boolean execute(String sql) throws SQLException;2)
Get result set using
ResultSet rs = statement.getResultSet();3)
And yes, you are doing correct thing when using:
while(statement.getMoreResults());
one very important line for your post:
1) check the date on which the original post was made and know that your post is very redundant.
one very important line for your post:
1) check the date on which the original post was made and know that your post is very redundant.
Just to point out, it's not redundant, I've found it helpful!
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.