Page 1 of 1

About Question enthuware.ocpjp.v8.2.1911 :

Posted: Mon Jun 06, 2016 5:36 pm
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 ?

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

Posted: Mon Jun 06, 2016 9:36 pm
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.

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

Posted: Sun Jun 12, 2016 6:26 am
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.

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

Posted: Sun Jun 12, 2016 7:59 am
by admin
You are right. I missed that part. Fixed.
thank you for your feedback!
Paul.

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

Posted: Mon Aug 29, 2016 8:17 am
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

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

Posted: Mon Aug 29, 2016 9:21 pm
by admin
You are right. Should be removed asap.
thank you for your feedback!
Paul.