I can pass database connection to report via java code. Following is how I implemented:
DataSource datasourceOracle= (DataSource)initialContext.lookup("java:jboss/jdbc/BirtConn");
task.getAppContext().put("OdaJDBCDriverPassInConnection", datasourceOracle.getConnection());
My problem is the report is using multiple datasource. So I need to pass two multiple connection to report. How can I?
If you know the details of your connections inside your Java code, you could pass these details instead of just the JNDI names, like this:
task.getAppContext().put("conn1.username", "scott");
task.getAppContext().put("conn1.password", "tiger");
task.getAppContext().put("conn1.url", "oracle:jdbc:thin:#//oracledb:1521/orcl");
task.getAppContext().put("conn2.username", "hr");
task.getAppContext().put("conn2.password", "x");
task.getAppContext().put("conn2.url", "oracle:jdbc:thin:#//other-db:1521/xyz");
Inside the report, you can then use the dataset's property binding dialog to set the values from the context, e.g. for your first data source:
Database URL: reportContext.getAppContext().get("conn1.name");
User Name: reportContext.getAppContext().get("conn1.username");
Password: reportContext.getAppContext().get("conn1.password");
Related
I'm using hsql 2.3.3. According to documentation I can fix this either by adding additional statement to the sql
SET DATABASE SQL SYNTAX ORA TRUE
or by adding property to the url
url: jdbc:h2:mem:test;sql.syntax_ora=true
First one fixes the issue for me (so this is root cause of it), but I would like to use second one as it looks more generalized for me. But url property does't do the trick. What I'm missing?
The URL property works only if you create a new database with the connection property. The new database will then include the SQL statement and run it automatically at each startup.
I am having a problem. I have a query that checks one database table and updates another database table. I am using MySQL 5.1
UPDATE dldd.temp,test.temp
SET test.temp.name = dldd.temp.word
WHERE dldd.temp.id = test.temp.id
this is my SQL statement that is working fine. Now I want to execute this statement using Java PreparedStatement . The problem is I don't know how to write the Connection String to select two database i.e
"jdbc:mysql://localhost:3306/"+dbname+"?characterEncoding=UTF-8"
What should come in place of dbname. Can I select multiple db there.
Have a look at http://dev.mysql.com/doc/connector-j/en/connector-j-reference-configuration-properties.html.
If the database is not specified, the connection is made with no default database. In this case, either call the setCatalog() method on the Connection instance, or fully specify table names using the database name (that is, SELECT dbname.tablename.colname FROM dbname.tablename...) in your SQL. Opening a connection without specifying the database to use is generally only useful when building tools that work with multiple databases, such as GUI database managers.
I need to create H2 file db on demand(first connection) from backup-ed script.
As I understand it could be done only by using two different urls:
jdbc:h2:file:sampledb;INIT=RUNSCRIPT FROM 'create.sql'; (Should be executed only one time)
jdbc:h2:file:sampledb;IFEXISTS=TRUE;
The problem is that in application connection to db is coming from JNDI so I should set up only one correct url. Does any ability exist to specify parameters based on some condition?
And how to get this conditionn from H2? (Something like jdbc:h2:file:sampledb;!{dbixists}=runscript...). Or some ternary operation is allowed?
I would simply include IF NOT EXIST clauses inside the create.sql script and run it everytime. It would create the DB model only if there is no proper model at all.
I want to know how to run FileMaker(FMP pro) database command in java. I have got the connection to database,but not sure how to execute below query.
Get(AccountPrivilegeSetName)
ref:
http://www.filemaker.com/11help/html/func_ref2.32.4.html#1051898
You will need to add a calculation field in FileMaker to return as the result of the JDBC query. This is because you cannot call functions via JDBC, you can only retrieve field values.
From within a java code - where I already have a connection to a database - I need to find the default schema of the connection.
I have the following code that gives me a list of all schemas of that connection.
rs = transactionManager.getDataSource().getConnection().getMetaData().getSchemas();
while (rs.next()) {
log.debug("The schema is {} and the catalogue is {} ", rs.getString(1), rs.getString(2));
}
However, I don't want the list of all the schemas. I need the default schema of this connection.
Please help.
Note1: I am using H2 and DB2 on Windows7 (dev box) and Linux Redhat (production box)
Note2: I finally concluded that it was not possible to use the Connections object in Java to find the default schema of both H2 and DB2 using the same code. I fixed the problem with a configuration file. However, if someone can share a solution, I could go back and refactor the code.
Please use connection.getMetaData().getURL() method which returns String like
jdbc:mysql://localhost:3306/?autoReconnect=true&useUnicode=true&characterEncoding=utf8
We can parse it easily and get the schema name. It works for all JDBC drivers.