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.
Related
I'm using JdbcTemplate.execute() to call a SP connected with SQLServer database.
With the same parameters, when I execute the SP directly in SQL Server Management Studio it finishes within 1s, but when I use JdbcTemplate in java it execute over minutes with causes severe performance issue.
Note the stored procedure contains "SET ANSI_NULLS ON" and "SET QUOTED_IDENTIFIER ON"
After some testing I finally find that the issue lies on blank values judgement in my SP:
I have some default parameters for the SP and set them as #A nvarchar(255)='', then during the logic I need to use them as logic condition: if(#A is not null and rtrim(ltrim(#A)) <>'')
Just that simple and it works totally good in the Management Studio.
After change that init to #A nvarchar(255) and use if(#A is not null), it also returns the results in JdbcTemplate... so there should be some inner logic for JdbcTemplate to do that empty check but I'm not sure why and how.
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");
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 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.
I am using an APACHE DERBY database, and basing my database interactions on EntityManager, and I don't want to use JDBC class to build a query to change my tables' names (i just need to put a prefix to each new user to the application, but have the same structure of tables), such as:
//em stands for EntityManager object
Query tableNamesQuery= em.createNamedQuery("RENAME TABLE SCHEMA.EMP_ACT TO EMPLOYEE_ACT");
em.executeUpdate();
// ... rest of the function's work
// The command works from the database command prompt but i don't know how to use it in a program
//Or as i know you can't change system tables data, but here's the code
Query tableNamesQuery= em.createNamedQuery("UPDATE SYS.SYSTABLES SET TABLENAME='NEW_TABLE_NAME' WHERE TABLETYPE='T'");
em.executeUpdate();
// ... rest of the function's work
My questions are :
This syntax is correct?
Will it work?
Is there any other alternative?
Should I just use the SYS.SYSTABLES and find all the tables that has 'T' as tabletype and alter their name their, will it change the access name ?
I think you're looking for the RENAME TABLE statement: http://db.apache.org/derby/docs/10.10/ref/rrefsqljrenametablestatement.html
Don't just issue update statements against the system catalogs, you will corrupt your database.