Seting Schema for HSQLDB in JDBC connection - jdbc

How does one set the schema for HSQLDB in the JDBC URL itself.
Kinda how you can do in MySQL with jdbc:mysql://localhost:3306/
-EDIT-
My current DB url looks like this
jdbc:hsqldb:file:C:\\hsqldb\\dbname
Also inside the dbanme there is a schema newSchema, which can be set using
set schema newSchema,
how do i do this using the jdbc URL itself.

have you already tried the standard protocol?
"jdbc:hsqldb:hsql://[HOST]:[PORT]/myDBName"
How are you trying to connect? through a standalone app or by creating a resource?
You might have seen this but still check here if not done:
http://hsqldb.org/doc/2.0/guide/dbproperties-chapt.html#dpc_connection_url

I think need to specify the port number like as shown //192.0.0.10:9500

UPDATE:
I have been doing some more testing. The suggested solution appears to be ineffective.
For example; if I set the schema to Test I still may not use SQL on tables in that schema. Essentially that extra stuff I put in there has no effect, even though I thought it was OK.
select * from BOOKMARKS;
SEVERE SQL Error at '<stdin>' line 5:
"select * from BOOKMARKS"
user lacks privilege or object not found: BOOKMARKS
SquirrelSQL has an option for an initial schema, so queries there work OK. The sqlTool accepts the URI but doesn't change/select the schema. It is slightly frustrating that I can't see HOW to report the current schema name in use btw.
So this answer doesn't solve the problem; I'm leaving it here because it will save the next person time when they find a good answer to the challenge.
back to the drawing board ...
original suggestion ...
I'd like to do this too. For example with mysql the example is:
mysql -h hostname:port schema
The port number, being one port per database. Now in HSQLDB, the URL is one database within a Catalog (that's how they spell it). Here's the solution I came-up with. I have ...
databsee: dev
schemas
public
test
In my RC file, ~/.config/sqltool.rc ...
urlid dev_test
url jdbc:hsqldb:hsql://localhost/dev;set schema test;
username programmer
password secret
I can use the connection ID dev_test to link to the test schema, the normal default is public. And you can run the sql tool with:
java -jar /usr/lib/hsqldb/lib/sqltool.jar --rcFile=~/.config/sqltool.rc dev_tmp
That approach worked with a Groovy Sql connection:
url: 'jdbc:hsqldb:hsql://localhost/dev;set schema test',
...
Worked just how I'd want it. So what I can do is append the schema I want to that URL connection string string. It may no be the solution but it will do what you describe.
Looking at the connection protocol: there is NO option for a schema nor for a catalog. So catalog will be part of your URL, eg. if you use a file base database, that is one catalog.

Related

Jetbrains Datagrip cannot connect sql server without specify database

i try to use Datagrip as my primary sql server query tools, bit i meet a problem that i can not move forward.
When i setup the project data source, i have to choose a Database, otherwise it will goto the default tempdb, how i can work like sql server management studio, that i can see all database list.
i have tried both jTds and Microsoft drivers, both not works.
or can i choose multi-database? i do not want to create one data source for one database.
if i connect to mysql, it works like expected.
tks
It is possible to connect without specifying the database. Just leave this field blank. After entering other settings (host, port, user, password), go to Schemas tab in Data Source properties and select all the Databases and schemas you want to work with. Then invoke Synchronize action for this Data Source in Database tool window.
DataGrip 2016.2 EAP claims to have support for showing multiple databases. See https://blog.jetbrains.com/datagrip/ and find for "Database View". Unfortunately, as of the date I'm writing this, it doesn't seem to work at all.
Unfortunately, Andrey's suggestion did not work for me.

What is the format of a .NET connection string?

I can find dozens of examples of a connectionString entry in Web.config, but there appears to be no comprehensive definition of the values in the string. What do the following mean:
Data Source -- This appears to be the server identity, but that could be a misinterpretation
Initial Catalog
AttachDbFileName -- Seems to be the file name of the DB file, but how does this relate to Initial Catalog? And what does |DataDirectory| mean when included in the name?
Integrated Security -- I assume that "True" means that "Windows Authentication" is used vs "SQL Server Authentication", but that's only a guess.
UserID/Password -- Used only in a few odd examples. Not clear when these might/might not be needed.
server -- I see this in some rare examples -- how different from Data Source?
database -- Ditto.
MultipleActiveResultSets -- ??
That's all documented right here on MSDN.
DataSource: The name or network address of the instance of SQL Server to which to connect.
Intial Catalog: The name of the database that will be in scope when connecting.
AttachDbFileName: he name of the primary database file, including the full path name of an attachable database. AttachDBFilename is only supported for primary data files with an .mdf extension.
Integrated Security: When false, User ID and Password are specified in the connection. When true, the current Windows account credentials are used for authentication.
User ID / Pasword: Used for SQL authentication.
Server: Similar purpose as DataSource, but appears to support different syntaxs depending on your needs.
MultipleActiveResultSets: When true, an application can maintain multiple active result sets (MARS). When false, an application must process or cancel all result sets from one batch before it can execute any other batch on that connection.
There is a lot more detail on each of these in the documentation.
You can also refer to the site http://www.connectionstrings.com
It is a great resource when it comes to play with connection strings for various database systems

Trouble setting currentSchema for DB2 on Glassfish

I've been working to move an application from MySQL to DB2, and am currently running into trouble with currentSchema on deployment.
The query:
SELECT count(*) FROM SomeTable WHERE BooleanColumn=1
will give me an error ( SQLCODE=-204) which means the object doesn't exist.
If instead I issue the query like this:
SELECT count(*) FROM SCHEMA.SomeTable WHERE BooleanColumn=1
Everything works as I would expect.
It seems like I should be able to set this to default to a schema somewhere, and at this point I have focused on the JDBC connection pool in Glassfish. It seems like I would usually be able to build a JDBC URL something like "jdbc:db2://SERVER_NAME:PORT/DATABASE:currentSchema=SCHEMA_NAME;", and currentSchema would take care of my needs, but I don't know how to do that in the admin control for Glassfish. I obviously don't know a lot about Glassfish - it is very likely I am looking in the wrong place.
I have the "Additional Properties" portion configured something like this:
Blah. I guess I'm too new to embed pictures...this link is this:
http://i.stack.imgur.com/IqUQd.jpg
Any help in getting this setup would be great...I don't want to have to hunt down every table reference and preface it with the schema name.
You can issue this statement in the same connection:
SET SCHEMA = my_schema;
By default, DB2 uses your username as the schema.

Oracle XE query log

In Postgres you can switch on query logging, resulting in a file containing all queries issued by any client.
Is there a similar possibility in Oracle XE? How do I switch it on and where do I find the resulting file?
You would:
alter session set sql_trace=true;
The trace file will be in the udump subdirectory under the installation directory.
Edit: Actually the docs say that sql_trace is deprecated in 10g: http://download.oracle.com/docs/cd/B19306_01/server.102/b14237/initparams205.htm#REFRN10208
It looks like DBMS_SESSION is the way to go now:
eg.
EXECUTE DBMS_SESSION.SESSION_TRACE_ENABLE(waits => TRUE, binds => FALSE);
http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/sqltrace.htm#CHDDGCCB
If you're targeting a specific application, you might find useful to use p6spy which is "an open source framework that intercept and optionally modify database statements"
Can be used with JBoss, ATG, Orion, JOnAS, iPlanet, WebLogic, WebSphere, Resin and Tomcat.
If you log into the web admin interface, and go into administration, you'll "Top-SQL" .... It has a search functionality, you can supply part of the query your looking for. I find that to be very helpful.

Spring Datasource and Database Schema

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.

Resources