1

I am executing the below query from my Java code:

SELECT * FROM JSTORE.EMPLOYEE

Where 'JSTORE' is the Schema name and 'EMPLOYEE' is the table.

Can I set the schema name to be used as JSTORE so that I needn't specify it in my queries always? I am using Oracle databse.

1
  • 1
    Maybe, in the JDBC URL that you use to connect to your database. But if, and how, depends on what database and what JDBC driver you're using. Commented Aug 22, 2012 at 9:39

2 Answers 2

2

If that schema name is the same as the user name your application is using to connect to the database, then you don't need to specify the schema name (through Java or SQL*Lite).

If the schema name varies through the application, then I would probably have the schema name present in the SQL to avoid mistakes. Just think about what can go wrong if you ALTER SESSION in a connection pool. It can still be configurable and the process can be automated using some Java code to generate the SQL for you (which you probably should have anyway).

Sign up to request clarification or add additional context in comments.

Comments

2

You can execute this SQL:

ALTER SESSION SET CURRENT_SCHEMA=JSTORE

Note that you need to execute this for each now connection that you make (one Oracle session == one Java Connection object).

Be careful when you use pooled connections; if they need different schemas, you need to restore the default before returning them to the pool.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.