alter session set current_schema problem with jdbc ?

Hello experts,
Is there a issue executing 'alter session set current_schema jdbc=STUFF'
to oracle thru JDBC.
It executes but does not alter the schema for subsequent queries from within the same connection.
Thanks
WaponiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tangchunfengCommented:
alter session set current_schema =scott
select count(*) from emp;
WaponiAuthor Commented:
My typo
 alter session set current_schema=STUFF
executes but does not alter the schema for subsequent queries from within the same connection.
Thanks
tangchunfengCommented:
it works
java 1.6.0.22 / ojdbc6.jar v12.0.1.0

package jdbc;

import java.sql.*;

public class OracleSetSchema {

      public static void main(String args[]) {
            try {
                  // url="jdbc:oracle:thin:@redhat:1521:orcl";
                  String ls_sql = "select count(*) from dd";
                  // select table_name from dba_tables where owner=:b0 order by
                  // table_name
                  String ls_sql_alter = "alter session set current_schema =ggtest";

                  DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
                  // new COM.ibm.db2.jdbc.app.DB2Driver());
                  // new com.microsoft.jdbc.sqlserver.SQLServerDriver());

                  Connection conn = null;
                  try {
                        conn = DriverManager
                                    .getConnection(
                          "jdbc:oracle:thin:@192.168.1.42:1521:test", "scott",
                          "tiger");

                        Statement stmt = conn.createStatement();

                        int rt = stmt.executeUpdate(ls_sql_alter);
                        System.out.println("alter result =" + rt);

                        Statement stmt2 = conn.createStatement();
                        ResultSet rs2 = stmt2.executeQuery(ls_sql);
                        rs2.next();
                        // count
                        System.out.println(ls_sql + "=" + rs2.getLong(1));

                        rs2.close();

                  } catch (SQLException e) {
                        e.printStackTrace();
                  } finally {
                        // finally
                        // {
                        // try { stmt.close(); }
                        // catch( Exception e ) {}
                        //
                        // try { con.close(); }
                        // catch( Exception e ) {}
                        // } // end finally clause
                        if (conn != null) {
                              conn.close();
                        }
                  }

            } catch (Exception ee) {
                  ee.printStackTrace();
            }
      }
}
riazpkCommented:
You might be grabbing (different) connection before executing any query.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
WaponiAuthor Commented:
Thanks,
I was getting a new con inbetween the alter and the statement.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.