Two resultset objects
IS it possible to define two resultset objects with two different queries inside the same DB class?java.sql.SQLException: Invalid state, the ResultSet object is closed.
at net.sourceforge.jtds.jdbc.JtdsResultSet.checkOpen(JtdsResultSet.java:299)
at net.sourceforge.jtds.jdbc.MSCursorResultSet.next(MSCursorResultSet.java:1123)
at DB5.getDetails(Daily_Quote_Response_report.java:238)
at Daily_Quote_Response_report.main(Daily_Quote_Response_report.java:74)
java.util.List items = null;
String query;
String query2;
try {
query =
"select * from oqrep_except_resp_summary";
query2 = "select * from oqrep_except_resp_detail";
Statement state = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY);
ResultSet rs = state.executeQuery(query);
ResultSet rs2 = state.executeQuery(query2);
//cannot create two rs objects // ResultSet rs2 = state.executeQuery(query);
items = new ArrayList();Edited by: bobz on 03-Dec-2009 11:16
Edited by: bobz on 03-Dec-2009 11:16
Note: This thread was originally posted in the [Java Programming|http://forums.sun.com/forum.jspa?forumID=31] forum, but moved to this forum for closer topic alignment.
Similar Messages
-
Using two resultset objects?
hi guys,
I have always created on ResultSet and used that over and over again...I now have a situation where inside a while (rs.next()) I have to create another SQL query. Does this mean I should create a NEW Statement from the same Connection, and then have a new ResultSet
Statement secondStatement = conn.createStatement();
ResultSet secondResultSet = secondStatement.executeQuery("My QUERY");Is this right?You will need to open another Connection, Statement and (presumably) ResultSet. However, if you are seeing logic like this, there is probably a better way to write the SQL statement itself (either via a UNION or a correlated sub-query) so that it only executes once.
- Saish -
Comparing two ResultSets for equality
Hello,
I wish to test if two separate ResultSet objects are identical.
By identical I mean that two different ResultSet objects are identical if
they contain the same rows in the same order, and each row contains identical values in the two ResultSets.
Two possibilities could be that the equals() method returns true or that the hashcode() method also produces the same hash value if the objects are identical as described.
I haven't been able to find any documentation on this issue.
Does anyone know if either (or both) of these methods have the contract as described above? If so are they guaranteed?
I can see several potential problems here. Performance with a large ResultSet, duplicate rows, and the ordering of rows not being guaranteed?
Thanks in advance.
TimTwo possibilities could be that the equals() method
returns true or that the hashcode() method also
produces the same hash value if the objects are
identical as described.I can tell you without looking anything up that these methods do not do that, as doing that would require them to scan the entire result-set, and JDBC tries to avoid doing useless processing. You are going to have to write this code yourself. -
How can we add two resultsets in java ?
screen_simu wrote:
Is it something we can do in java?OP, if you can do it in SQL, that likely would be better. On the other hand, do you mean that want to add the results from two resultsets that might perchance be different? IOW ... if both ResultSets produce the same columns, then a UNION join in SQL:select
tableA.empl_name,
tableA.empl_id
from tableA
UNION
select
tableB.empl_name,
tableB.empl_id
from tableBBut, if you want to select out specific columns from differing RS's, then you might want to do this:
List<Empl> empList = new ArrayList<Empl>();
public class Empl {
private String empl_id;
private String empl_name;
private Double empl_wage;
public void setName(String name) {
empl_name = name;
// ... etc, other method implementations ...
// ... SQL stuff ...
String sqlA =
"select"
+" tableA.empl_id,"
+" tableA.empl_wages"
+" from tableA";
// ... rsA is the ResultSet from the tableA selection
Empl empl = null;
while (rsA.next()) {
empl.setID(rsA.getString(1));
empl.setWage(rsA.getDouble(2));
empl.setName(processTableB(empl.getID()));
empList.add(empl); // new Empl Object for each employee
public String processTableB(String id) {
String name = null;
String sqlB =
"select"
+" tableB.empl_name"
+" from tableB"
+" where tableB.empl_id = ?"
// ... set up PreparedStatement ... using passed in id
// ... process ...
while (rsB.next()) {
name = rsB.getString(1);
return( name );
}Above code untested, but hopefully you get the idea. -
??how to compare two resultsets??
hi all!
i need to find out whether two resultsets contain the same data.
the only way i know how to do it in java is to put them into a while loop and fetch the contents first and then compare the contents.
but is there an easier way to compare resultsets?
does anyone know how to compare two resultsets without extracting the data?
the code example here executes two identical queries on an oracle database, compare and print the resultsets.
public ResultSet getResultset(String query)
ResultSet rs=null;
try { rs=Stmt.executeQuery(query); }
catch(Exception e) { e.printStackTrace(); }
return rs;
public static void main(String[] args) {
ResultSet r1=null;
ResultSet r2=null;
try {
database db = new ddatabase();
r1=db.getResultset("Select 'name' from person");
r2=db.getResultset("Select 'name' from person");
if (r1 == r2) {
System.out.println("ok");
System.out.print(r1);
System.out.println();
System.out.print(r2);
else {
System.out.println("not ok");
System.out.print(r1);
System.out.println();
System.out.print(r2);
jdbc.cleanup();
catch(Exception e) {e.printStackTrace();}
and here is the output:
F:\java rs_compare
not ok
oracle.jdbc.driver.OracleResultSetImpl@4413ee
oracle.jdbc.driver.OracleResultSetImpl@786e64
as you can see the resultsets are different though the data they contain have to be the same.
so the 'if(resultset#1 == resultset#2)' does not work.
thanks for any help
best regards
5ithl0rdDon't cross-post.
I'll bet ResultSet implementations don't override equals() to provide "deep equals" behavior, in which case it'll be no different than using "==".
It's a bad idea to compare two ResultSets this way. You'll have to load both into objects or data structures and compare those in a "deep" way.
Besides, the ONLY way two ResultSets could be different, given the same query, would be if there were multiple clients that could write to the table between queries and change the underlying data. If your two queries are sufficiently isolated, I'd say that the same query will return the same ResultSet.
% -
Oracle Function returns a Ref Cursor to a ResultSet object - Performance
My program calls an Oracle PL/SQL function which returns a ref cursor to a ResultSet object. I know that the function runs to completion relatively quickly when i run it in an anonymous block but when the call is made through my Java application the resultset takes about 30 mins to return. Below is a snippet of my code:
currentConnection = ConnectionManager.getInstance().getConnection();
reportStmt = currentConnection.prepareCall("BEGIN ? := ENVISION.PKG_WMS_TO_AP.F_REPORT_CI_SC_HOLDING(?,?); END;"); reportStmt.registerOutParameter(1, OracleTypes.CURSOR);
reportStmt.setString(2, invoice.getCrewHQ());
reportStmt.setDate(3, invoice.getWrCompletionDate());
reportStmt.execute();
reportRS = ((OracleCallableStatement) reportStmt).getCursor(1);
Through a debugger I see that the second last statement (reportStmt.execute()) runs quickly. It is only when I step into the last statement that the debugger takes up to 30 minutes.
Any thoughts?Flynn,
The Internet is a dynamic place. After nearly two and a half years, there is a chance that a link will change. This is the new URL for the relevant Web page:
http://asktom.oracle.com/~tkyte/ResultSets/
Good Luck,
Avi. -
Two response objects within one servlet...
Heya guys, quite new to java and got stuck for the whole day on this.
I need to combine two responses inside one servlet. One response retrieves picture from the database and it works fine. Another one retrieves text from database also works fine on its own. Second i try to use both end up with hundreds of exceptions.
Any idea what to do, not how...but what???
ThanksCompiling 1 source file to F:\gopal\weba\WebApplication6\build\web\WEB-INF\classes
F:\gopal\weba\WebApplication6\src\java\NewServlet.java:48:
processRequest(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse,javax.servlet.http.HttpServletResponse) in NewServlet cannot be applied to (javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
processRequest(request, response);
F:\gopal\weba\WebApplication6\src\java\NewServlet.java:57: processRequest(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse,javax.servlet.http.HttpServletResponse) in NewServlet cannot be applied to (javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
processRequest(request, response);
2 errors
F:\gopal\weba\WebApplication6\nbproject\build-impl.xml:295: The following error occurred while executing this line:
F:\gopal\weba\WebApplication6\nbproject\build-impl.xml:149: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 2 seconds)
You cannot use two response object. -
Two remote objects calls on the same php class
Hi to all,
I've encountered a strange issue while developing with remote objects.
I've a mxml component with an init() method inside which is called by a menu.
When the init() method is called it makes 7 remote object calls which are bound to some components' dataprovider.
Among this calls I've got 2 remote object which refer to the same remote class. This because I have to call the class twice and the bind the result to two different combobox. Below you find the code:
<mx:RemoteObject id="myFile" source="myRemoteClass" destination="amfphp" showBusyCursor="true" makeObjectsBindable="true" fault="traceFault(event)"/>
<mx:RemoteObject id="myXls" source="myRemoteClass" destination="amfphp" showBusyCursor="true" makeObjectsBindable="true" fault="traceFault(event)"/>
in the init function I make this calls:
myFile.listDir("dir_1")
myXls.listDir("dir_2")
then in the mxml code I bound the result of myFile to combobox1 and the result of myXls on combobox2.
The problem arise when I call the myXls' listDir method. When I call it I receive the following error:
code:
Client.Error.DeliveryInDoubt
Message:
Channel disconnected
Detail:
Channel disconnected before an acknowledgement was received
The strange thing is that not only the myXls object returns this error, but also all the other 6 remote object return the same error above.
I'm not sure, but I guess that the error could be caused by the two remote object which call the same php remote class. If I comment one of the two calls everything works fine.
Do you have any suggestion about?
Thanks!!
Bye
LukeHi Jan.
1) We have the 2 VO, each with 3 rows to fill in data. What I mean is that when i just fill in all the fields for the first row of the first VO, and the value of one of these fields is bigger than 50, then after the exception is thrown and the message is displayed, the fields for the first VO are duplicated and shown in the second VO as if the user had inserted them.
2) We tried yesterday the validateEntity and a Method and Atributte Validator approaches after reading that white paper with the same results.
The validation is correctly done using any of the those methods.
I will try to reproduce this issue with the HR schema.
Thanks in advance once again. -
Two authorizations objects with OR function instead of AND
Hi,
We have created two authorization (RSECADMIN) objects for a CRM InfoProvider:
Organizational responsible
Delivery unit.
Both the two authorized relevant InfoObjects are used in the query.
In the query we have used a two authorization variables.
Now only values in the authorizations are checked where Organizational responsible are true AND Delivery unit are true.
Is it possible to check the authorization where:
Organizational responsible is true OR Delivery unit is true??
Please help!
Regards,
Jos.Hi,
hmmm Andreas, I must comment on that:
what is required is to show any record having Object1 = True OR Object2 = TRUE.
Logically it is the same than asking:
Don't show records having (Object1 NOT True) AND (Object2 NOT True), correct me if I am wrong there (this is pure Boolean math...)
Because BW doesn't support this it doesn't mean that ANY system cannot do it.
Simply put with SQL
SELECT * FROM TABLE
WHERE OBJ1 = TRUE OR OBJ2 = TRUE works perfectly in ANY RDBMS.
also
SELECT * FROM TABLE
WHERE NOT OBJ1 <> TRUE AND OBJ2 <> TRUE would work as well.
It is just that BW always perform an AND when you filter two different objects.
Jos could achieve what he wants by setting up some restricted key figures and work it out with conditions but definitively not with standard authorizations.
Alternatively, as I already mentioned, compounding objects would work but not without modeling effort. Finally I believe that with user exits it would also be possible... I don't have time but I would as well investigate bringing both objects along with the provider in a multi and verify if that couldn't be done by semi/standard means finally...
hope this shed some lights on the issue....
regards,
Olivier. -
Two cost objects Sales order , OKB9 business area +order
Hi All,
While posting intercompany IR system thronging below error messageu2026
Enter only one true account assignment
Message no. KI249
Diagnosis
You made assignments to several objects in CO (cost center, order, project etc.). 2 of these have been created as true objects.
System Response
You are allowed only one account assignment for each cost-relevant account.
What we found in our system:
Conflict: Actual Sales Order 3487909 is linked to PO via account assignment category 4& IC dummy sales order (OKB9 config Business area 3000 + order 807898 assigned.
Due Two cost objects cannot be linked to one IR G/L account booking.
What is the best solution for this to post Intercompany IR with conflict two cost objects.
Regards,
AdiHi All,
we facing an issue with sales order cost objective vs OKB9 cost object.
For IC PO service material, we assigned account assignment category 4.Reasonis Service material was not showing on G\R account.
The G\L account 7898788, we assigned to Service Item (material type DIEN) , for G\Cost 7898788 cost element is assigned in OKB9. Combination business + order 3478787.
Now conflict with sales order cost objective vs OKB9 internal order cost object.
While posting intercompany IR posting system thronging below error messageu2026
Enter only one true account assignment
Message no. KI249
Diagnosis
You made assignments to several objects in CO (cost center, order, project etc.). 2 of these have been created as true objects.
System Response
You are allowed only one account assignment for each cost-relevant account
How to resolve this issue.. Do I make any config changes in the system to overcome this issue?
Or any sub account to assinment in VKOA config for internal orderu2026
Regards,
Adi -
Two Business Objects to fill a Data Grid/table using Anchors?
Hi,
I have a SAP standard tile were a table (grid) is filled by an Business Object. I want to add an additional column and retrieve the value from another Business Object.
My questions
1) Can I use Anchors to automatically set the relationship between two Business Objects A & B, so that I can just Drag & Drop an additional field from Business Object B to the DataGrid of Business Object A in the design screen without writing additional code?
2) Some BO's do come with a predefined relationship to other BO's, but in the case of I have to write a supply function do I have to use a specific "Data Source Type" such as "Business Object", "BusinessQuery" or "Business CollectioN"?
3) I already tried to write a supply function, but I realized that the system does return for some BO's or BS's a object instance, if I call "gFactory.newBusinessQuery". Is there any logic/restriction behind?
I know I can use RowLoaded2 and a unbound column, but I want to know if this approach is also possible?
Thank you for any help,
Regards,
AndreasHi Andreas,
The answer to your question is YES. You can very well do it without any changes at the code level.
The scenerio can be implemented using a concept called JointField Mapping in MAS.
Scenerio 1 :
If you want to display the extra field from another BO in a list tile on the click of a search button from the search tile , then
Please do the following :
1. Select the Busines Query that you have associated to the search tile and go to properties from the View Designer.
2. In the properties, Click on the Joint Field Mapping and select the BO where the extra field id present and select the primary key, Segment Field associated, (extra field)BO Property that you want to display in the list tile.
2. Add a new control (new Field) in the List tile - ie, From the Toolbox (Tileset COntrols).
3.Go to properties of the newly added control. Associate the anchor as the same achor as the list tile was pointing to earlier. for eg : Y_BOCAPGEN.
4. Then Go to BCOLFieldName property and give the property name as the newly added BO property name(New field).
After everything is modelled, You will be able to see the extra field in your application!!!!
NOTE : Ofcourse, After the Successful generation.
Scenerio 2 :
If you want to display an Extra Field in a Detail tile,
1. Go to Relationship of the BO from the Detail tile and go to properties.
2. In the properties, You can find the Joint Field Mapping porperty.
3. This property is again modelled as explained in scenerio 1.
Hope, It would have definetly helped and answered your query.
Have a good day!!
Best Regards,
Vignesh Ravikumar. -
Uix two view-objects on one entity-object synchronize
Hi All
I want to add some uix pages to an old project using ADF UIX and Business Components.
I have an entity object to a table witch about 50 fields.
Now I create two view objects due to a better performance. One witch seven attributes for the overwiew and one with all attributes for the detail page.
They are related via a view link.
I create the overview as a read-only-table and the detail-page as an input-form.
The proplem is that the synchronization don't work. The detail page shows the first dataset ever.
Has anyone a solution or a tip where I can found that?
Is where a performance problem if I use one view-object for both pages?
Thanks in advance
RogerUse custom DataAction for the first page:
package controller;
import oracle.adf.controller.struts.actions.DataAction;
import oracle.adf.controller.struts.actions.DataActionContext;
public class Class1 extends DataAction
protected void validateModelUpdates(DataActionContext actionContext)
//super.validateModelUpdates(actionContext);
// put you custom validation here
}http://www.oracle.com/technology/products/jdev/collateral/papers/10g/ADFBindingPrimer/index.html#usingdataaction
Message was edited by:
Sasha
Message was edited by:
Sasha -
Do you know about any possible Java bugs with JDK update?
In my case, my code stopped working.
Here is what I have. There are two similar objects, but Object 1 has key, and Object 2 (same as Object 1) has no key. I need to compare both, and if they are equal, I need Object 1 to assign key to Object 2.
It worked before. How I can get around.
Please help me if you can.
Respectfully,
AlexLet me change the question:
"Can we compare two objects one with key and another one without key? How? -
Synchronising two different objects
Hi everyone,
I am asking for your help while i am writing an example code. I want to learn how to synchronise two differents objects.
The first class is actually a MIDlet, which has to increase a counter and display it until the second class send a message to the midlet. At this moment, the midlet has to display the message. I am actualy thinking about adding another thread, but lets speak only about the midlet and the calculator :)
I think there is a problem in my way of thinking, that's why i am asking for your help :
Here is an extract of my midlet code :
public class Main extends MIDlet implements CommandListener {
private static boolean isFromCalculator = false;
private static boolean displayUsed = false;
Command exitCmd = new Command("Exit", Command.EXIT, 1);
Command pauseCmd = new Command("Pause", Command.OK, 1);
TextBox tb = new TextBox("Principal", "", 200, 1);
int cpt = 0;
Calculator calc = new Calculator();
public Main()
calc.start();
tb.addCommand(exitCmd);
tb.addCommand(pauseCmd);
tb.setCommandListener(this);
public void startApp() {
process();
public void pauseApp() {
public void destroyApp(boolean unconditional) {
public void process()
// Tant que l'on a pas d'infos des deux autres threads, on compte !
while ( !isFromCalculator )
if ( displayUsed )
synchronized(this){
try{
wait();
catch (Exception e)
e.printStackTrace();
display("Principal : " + cpt + "\n", 1);
cpt++;
deroute();
public void display(String message, int time)
displayUsed = true;
tb.delete(0, tb.size());
tb.insert(message, tb.size());
Display.getDisplay(this).setCurrent(tb);
synchronized(this)
try{
wait(time);
catch (Exception e )
{e.printStackTrace();}
displayUsed = false;
notifyAll();
public void deroute()
if ( isFromCalculator == true )
// Manage Calculator message
display(calc.Message(), 1000);
isFromCalculator = false;
process();
public static void setBoolFromCalculator(boolean b)
isFromCalculator = b;
public static boolean isDisplayUsed()
return displayUsed;
}And here is my calculator code :
public class Calculator extends Thread{
private int iterator;
private boolean quit;
public Calculator()
iterator = 0;
quit = false;
public void run()
while ( !quit )
iterator++;
// 100 Boucles maxi
if ( iterator > 100)
quit = true;
try{
sleep(1000);
catch (InterruptedException e )
System.out.println("Calculator sleep error : ");
e.printStackTrace();
if (iterator % 10 == 0)
if ( !Main.isDisplayUsed() )
synchronized(this)
try{
wait();
catch(Exception e)
e.printStackTrace();
Main.setBoolFromCalculator(true);
public String Message()
return " Calculator - Iterator = " + iterator +"\n" ;
}May i ask your any advice ?
Regards,t00f wrote:
Hi everyone,
I am asking for your help while i am writing an example code. I want to learn how to synchronise two differents objects.Note that you don't "synchronize objects." You synchronize methods or blocks of code on objects (or, more properly I suppose, on their locks). This may seem like a petty distinction, but when you say "synchronize objects," it sounds like you think that you're controlling access to an object. That is not the case. If you need further explanation, let me know. -
" COMBINING TWO INFO-OBJECTS ! "
Hai Friends ,
I am having 2 info-objects : Info-object1 - length 60, Info-objec2 - Length -30. I have to combine these two Info-objects . Let anyone know me the procedure forcombining these two Info-objects : Info-object1,Info-object2 .
Waiting for your reply .Hi,
Create the infoobject which contain the string.
if CHAR1 is 30 and CHAR2 is 60, your new infoobject should be 90.
In the transformation/update rule you concatenate the two infoobject.
Concatenate is a function which is available in the formula builder, no ABAP needed
In the Routine you reference at the uploaded Data with:
concatenate COMM_STRUCTURE-infoobject1
COMM_STRUCTURE-Infoobject2
into RESULT.
Thanks & Regards,
Vipin
Maybe you are looking for
-
The latest two updates of Mozilla Firefox are not useful for me because of extremely slow printing of web pages. It was never a problem before. Same iMac and HP officejet printer. How can I either fix it, or revert to an earlier version of the browse
-
HT4623 Question: how do I get an app to complete the update?
I have an app that is trying to update, but it won't complete the update. It's seems to be stuck. I searched my problem online, did the recommended tips, but they did not work. How do it get the phone to complete the update?
-
I've just updated my operating system to 10.4.10 from 10.4.6. I manage a website designed by someone else, and they didn't define a font size for body text/paragraphs in our CSS. As a result, in the newest version of Safari, the portion of the site t
-
Defer Panel Updates not working for XY graph
I am using an XY Graph in Labview 8.2. I am making a lot of color changes and want to improve execution time by defering the panel updates while changing the colors. I set the VI/Panel/DeferPanelUpdates to true and do the updates. I can see the ot
-
SM:TMWFLOW_CMSSYSCOL Job failing
Hi, SM:TMWFLOW_CMSSYSCOL job getting failed daily. Below is the job log. Job started Step 001 started (program /TMWFLOW/CMSSYSCOL2, variant , user ID XXXXXXXX System XXX unknown in Transport Management System System unknown in Transport Management