About Question enthuware.ocpjp.v8.2.1911 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
ntotomanov
Posts: 6
Joined: Tue Jan 19, 2016 4:30 pm
Contact:

About Question enthuware.ocpjp.v8.2.1911 :

Post by ntotomanov »

Hello,

In a study guide I've been reading is stated that:
A Statement automatically closes the open ResultSet when another SQL statement is run.
ResultSet rs = stmt.executeQuery("select count(*) from species");
int num = stmt.executeUpdate("INSERT INTO species VALUES (3, 'Ant', .05)");
rs.next(); //throws exception
Could you please comment on this ?

admin
Site Admin
Posts: 10386
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1911 :

Post by admin »

The JavaDoc API description of the execute or executeQuery method doesn't say anything like that: https://docs.oracle.com/javase/7/docs/a ... ng.String)

https://docs.oracle.com/javase/7/docs/a ... ng.String)

You should ask the authors of the book why they wrote that.

HTH,
Paul.

leonbobster
Posts: 1
Joined: Sun Jun 12, 2016 6:23 am
Contact:

Re: About Question enthuware.ocpjp.v8.2.1911 :

Post by leonbobster »

I'm sorry it looks like you have mistake in your test:
I have at least two rows in my db with email in column 3.

Code: Select all

try (
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/cp.local?useSSL=false", "root", "");
            Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
        ) {

            ResultSet rs1 = stmt.executeQuery("SELECT * FROM as_user LIMIT 1");
            rs1.next();
            ResultSet rs2 = stmt.executeQuery("SELECT * FROM as_user LIMIT 1");
            rs2.next();
            System.out.println(rs2.getString(3));
            System.out.println(rs1.getString(3));

        }
I got:

Code: Select all

Exception in thread "main" java.sql.SQLException: Operation not allowed after ResultSet closed
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:896)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:885)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860)
	at com.mysql.jdbc.ResultSetImpl.checkClosed(ResultSetImpl.java:743)
	at com.mysql.jdbc.UpdatableResultSet.checkRowPos(UpdatableResultSet.java:211)
	at com.mysql.jdbc.ResultSetImpl.getStringInternal(ResultSetImpl.java:5244)
	at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5167)
	at OCP.main(OCP.java:39)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
also by the link you provided prev:
By default, only one ResultSet object per Statement object can be open at the same time. Therefore, if the reading of one ResultSet object is interleaved with the reading of another, each must have been generated by different Statement objects. All execution methods in the Statement interface implicitly close a statment's current ResultSet object if an open one exists.

admin
Site Admin
Posts: 10386
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1911 :

Post by admin »

You are right. I missed that part. Fixed.
thank you for your feedback!
Paul.

ramy6_1
Posts: 124
Joined: Wed Feb 12, 2014 2:44 am
Contact:

Re: About Question enthuware.ocpjp.v8.2.1911 :

Post by ramy6_1 »

Hello,

Why this question part of 1z0-810 exam ?
ResultSet is not included at Oracle exam topics.

Also why it is a part from Date/Time API section ??

https://education.oracle.com/pls/web_pr ... id:1Z0-810

Kindly clarify

admin
Site Admin
Posts: 10386
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1911 :

Post by admin »

You are right. Should be removed asap.
thank you for your feedback!
Paul.

Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests