I have a Squeryl connection to an Oracle database.
How do I change the CURRENT_SCHEMA setting upon connecting?
In raw sql this would be done with
ALTER SESSION SET CURRENT_SCHEMA=<schema name>
How do I do this via Squeryl?
There are two ways:
org.squeryl.Schema has a method called name. If you override it and provide a name, each statement will use that name to reference the schema.
If you want to alter the implicit schema that a statement is executed against, then you'll want to execute what you posted above as JDBC. You should be able to find information on how to access the JDBC Connection associated with a Squeryl Session fairly easily.
Related
A user has been configured on Oracle. Via this user, I can create an ODBC connection and an OCI connection, and these both test fine in Win10. Using Alteryx with the ODBC and OCI connection, we try to write data to a new table.
The table is created and appears in PL/SQL with the expected column names. However, the rows are never written and the connection just hangs at this point.
What could be wrong? I am not an Oracle Admin
Based on comments you were expecting oracle to commit without executing "commit" command explicitly. It's not enabled by default in oracle so you have to turn it on.
It's not possible to turn this on for the database, but on client apps only.
E.g. "set autocommit on" command in SQL Plus.
So you need to check docs for the client application you're connected with (presumably Alteryx is the one). It might have such a feature.
I am trying to get all the schema from a database which I passed in the connection url in snowflake jdbc driver.
Observation :
I am getting all the schema from all the databases even though I pass wrong database.
wrong database/schema/warehouse does not validate during the connection creation time.
URL : jdbc:snowflake://XXXXX.region.aws.snowflakecomputing.com?role=custome_role&warehouse=test_wh&db=test_db&schema=test_schema &CLIENT_METADATA_REQUEST_USE_CONNECTION_CTX=true
Why Snowflake JDBC driver does not validate the wrong warehouse/database/schema during connection creation time or query execution time?
What I see is that there is no check on the DB name parameter being passed in the connection url.
The only check that is done is for Role and if the role is existent then all the db's for that will be listed.
Use
statement.executeQuery("show databases;");
And check if the list contains the requested database
I want to create a new database on an Oracle server via JDBC. I cannot seem to connect to the database without providing an SID: using a URL like jdbc:oracle:thin:#//[IP]:1521 results in an error of "ORA-12504, TNS:listener was not given the SID in CONNECT_DATA"
Alternatively, if I log into a specific SID, I can run most DDL commands except for CREATE DATABASE foo which fails with an error of "ORA-01100: database already mounted"
How am I supposed to create a database if I cannot connect to the server without specifying a specific database and cannot create a database if I am already logged into a specific database?
AFAIK creating a database needs an internal and direct connection which can only be done by logging in directly on the server (normally a user account called 'oracle').
One reason for that: users are stored in the database itself. No database = no user to connect to by an external client.
Please also note Justin's comment about oracles database schemas. This is probably what you are looking for
What you need are following commands:
CREATE TABLESPACE CREATE USER and few GRANT ... TO ... -- to have rights to connect and create objects, at least
I'm using the connection URL jdbc:hsqldb:file:/data/hsqldb/mydb;hsqldb.default_table_type=cached with HSQLDB 2.1. Issuing 'CREATE TABLE' does not persist anything (there's no .data file created). Issuing 'CREATE CACHED TABLE' explicitly works correctly, however. What have I missed?
The URL or connection property settings for the database are applied to new databases only. For an exsiting database, you should use SET DATABASE DEFAULT TABLE TYPE CACHED
I think I've fixed it: I wasn't issuing a SHUTDOWN command (I'm not exactly sure why my CREATE CACHED TABLE worked regardless, but never mind)
I am trying to declare a Spring datasource pointing to a DB2 database. Presently I am using a org.springframework.jdbc.datasource.DriverManagerDataSource to setup the connection but am not finding any way to specify the database schema in the database in the datasource bean. Could anyone help me on this?
Problem is there is no standard way to set the schema, each database has a different mechanism.
A work around is to set the schema as part of the db url...
For db2 the url will look something like:
jdbc:db2://SERVER_NAME:PORT/DATABASE:currentSchema=SCHEMA_NAME;
hope that helps...
Special note: make sure you add the semicolon ; at the end of the URL, otherwise you will get errors saying URL is invalid. Also make sure nothing after last ; exists (not even spaces).
There isn't a means to do this with the standard Spring namespace. Rob Harrop's response to a request to add the schema to the configuration:
In general, this kind of functionality should be pushed into the connection pool since there is no really elegant and performant way to do this via a decorator. The pool can set the schema once per connection it creates, whereas here you have to set it each time a connection is retrieved.
If you're desperate to set the proxy in your configuration, the submitter included some code for a proxy to allow the schema to be specified.
If your connection uses the owner of the schema as the user then that connection will point to that particular schema.
ie. If user user1 is the owner of the database schema named schema1 then if you connect to the database using user user1 then by default the connection will point to schema1.
We have used UserCredentialsDataSourceAdapter provided by spring to connect to different schemas based on the logged in user. This provides a datasource which is pointing to a particular schema based on the user. This uses a thread based login information. Each thread has to decide to which schema it has to connect and provide the user according to that.