Trouble setting currentSchema for DB2 on Glassfish - jdbc

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.

Related

Error while runneing select query in sql developer

I am using Oracle SQL Developer version 4.1.0.19.
So this can be a very simple issue but I cannot seem to find the solution anywhere as I have just started using SQL Developer.
I type in this query
create table Student(Stu_id INTEGER,Stu_name VARCHAR(60),Stu_email VARCHAR(60))
select * from Student
And when I Run the SELECT query, I get an error something like this:
Method oracle/jdbc/driver/T4CCallableStatement.isClosed()Z is abstract
I have no idea as to why this is happening , this may be very stupid but I cannot seem to find a solution.
BTW I am using Oracle 11g version.
How did you install SQL Developer? Can you download the zip off of OTN and extract it to a fresh directory and try running it from there?
Your error message indicates something VERY bad is wrong with one of the drivers. Which makes me wonder if you messed with one of the JARs or are attempting to use an old Oracle Client with a THICK connection.

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.

Seting Schema for HSQLDB in JDBC connection

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.

SQL Server linked server error message

I have a SQL Server 2005 database server set up with a linked server to an Oracle database.
When I try to run a delete or update query, I get the following error message:
Cannot fetch a row using a bookmark from OLE DB provider "OraOLEDB.Oracle" for linked server
The same code was working a couple hours ago while I was testing it, but suddenly it's stopped working. Has anyone seen this before and know a way to fix it/troubleshoot further?
The same queries executed in SQL Developer directly in the DB work fine. (I know it's something with the linked server, but I'm not sure what)
Any pointers would be appreciated.
Use EXEC('query') in following way:
Suppose, your previous query look like this:
UPDATE [MyOraLinkedServer]..[XYZ].[TABLE]SET [DAT_COL] = cast (getdate() as smalldatetime)
Change the above query with following query:
declare #NewValue smalldatetimeset
#NewValue = cast(getdate() as smalldatetime)
exec( 'update XYZ.TABLE set DAT_COL = ?', #NewValue ) at MyOraLinkedServer
NOTE:To make this possible you have to enable RPC on the linked server
In this way, it may solve your problem......

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.

Resources