How to edit datasource in IReport? - ireport

I have created a JDBC DB datasource in IReport 5.1.0 design.
Now I want to edit the datasource.
How to edit datasource in IReport? I don't find Edit datasource menu in IReport . Where is it ?

Right click on the root (report) and press edit query

Related

My table data got deleted when i restart my spring boot application after changing the value of 'spring.jpa.hibernate.ddl-auto'

My table data got deleted when i restart my spring boot application after changing the value of 'spring.jpa.hibernate.ddl-auto' to 'create' from 'verify'. why it is so? what should i do to get my data back?
I could see some drop query executing in my IDE console. Why it happened? can someone please explain?
Make the following change in application.properties
spring.jpa.hibernate.ddl-auto=none
You can read the official document of spring-boot.And the property is related to hibernate.hbm2ddl.auto in hibernate configuration.
Just change table name:
#Entity
#Table(name = "hms_pinlocator")

Set default schema = SOMETHING in oracle using Spring Boot and Spring JDBC

I am working now with oracle and spring jdbc but I don't want to use the schema in my sql statements:
Example: Select * from SCHEMA.table
Is there any way to set default schema in application.properties or application.yml?
Assuming you define your database connections using spring datasources, you can set the default schema when defining the datasource configuration:
spring.datasource.schema = #value for your default schema to use in database
You can find more info here: Spring Boot Reference Guide. Appendix A. Common application properties
After doing some research, looks like Oracle driver doesn't let you set a default schema to work with, as noted here:
Default Schema in Oracle Connection URL
From that post, you have two options:
Execute this statement before executing your statements:
ALTER SESSION SET CURRENT_SCHEMA=yourSchema
Create synonyms for your tables/views/etc (which I find really cumbersome if we're talking about lots of elements in your database).
I would advice using the first option. From what I see, Spring boot doesn't offer a simple way to execute a statement when retrieving the connection, so the best bet will be to use an aspect around the getConnection method (or the method that retrieves the connection from the data source) and execute the statement there.
From your comment, an easier way to solve it is by using a script in spring.datasource.schema:
spring.datasource.schema = schema.sql
And then a file squema.sql with the following:
ALTER SESSION SET CURRENT_SCHEMA=mySchema
In spring boot, I've found another way of doing it,
#Bean
#ConfigurationProperties(prefix="spring.datasource")
public DataSource dataSource(#Value("${spring.datasource.schema}") String schema) {
DataSource datasource = DataSourceBuilder.create().build();
if(!schema.isEmpty() && datasource instanceof org.apache.tomcat.jdbc.pool.DataSource){
((org.apache.tomcat.jdbc.pool.DataSource) datasource).setInitSQL("ALTER SESSION SET CURRENT_SCHEMA=" + schema);
}
return datasource;
}
I found another way to get around this by updating entity class with
#Table(schema = "SCHEMA_NAME" ,name = "TABLE_NAME")
If you are using hikari, use spring.datasource.hikari.schema=YOUR_SCHEMA.
Works for me with SpringBoot + tomcat using Oracle.
I was having issues with the currently accepted answer; specifically, the schema would only be changed from the initial connection. If your app uses a connection pool, you need to configure the pool to apply SQL for each connection.
For instance, using the default jdbc pool in Spring Boot 1.5.x (Tomcat):
spring.datasource.tomcat.init-s-q-l = ALTER SESSION SET CURRENT_SCHEMA=mySchema
Connecting to the database as your user, you can create a trigger that will change the schema each time you login:
CREATE OR REPLACE TRIGGER LOGON_TRG
AFTER LOGON ON SCHEMA
BEGIN
EXECUTE IMMEDIATE 'ALTER SESSION SET CURRENT_SCHEMA = foo';
EXCEPTION
when others
then null;
END;
/
Another option is to create a datasource wrapper. Create the datasource as normal and then create the wrapper that forwards all methods except for the getConnection methods. For those I just added SQL to set the schema. We have multiple datasources and this allowed us to specify a different schema for each datasource. If anyone knows if there's an issue with this I'd love comments. Or if there's an alternative that uses the properties.

dynamically setting DataSource properties for Spring jdbc

I'm using spring jdbc and I want my application to connect to different DBMS as oracle,mySQL, SAS etc.
the application should work on different systems, so the connection properties are not priorly known.
Ideally, the user will be able to select connection type from a list and then set the connection properties (username,password...)
Can you please help me :)
Have a look at this post: http://examples.javacodegeeks.com/enterprise-java/spring/jdbc/spring-jdbctemplate-example/
There you can see the normal jdbctemplate use. As you can see the dao has got the datasource injected: you can basically do the same, but you need not to set the org.springframework.jdbc.datasource.DriverManagerDataSource properties in the applicationContext.xml. You will do it at runtime according to user choice. That basically means all the daos have to get the datasource needed params in input.
Hope this helps.

populate values in textbox from database on selected Index changed event of dropdown in jsp hibernate and spring

I have a dropdown. On selecting any value in dropdown iwant to populate values in textbox from database using spring and hibernate and jsp
First setup your web application with jsp, spring and hibernate.
Use javascript on the page which onChange event of drop down makes an ajax call to your service and set the textbox.

How can I change the value for application.properties dynamically?

How can I change the value for application-properties.xml file dynamically through the program in the spring hibernate framework. Actually Iam using config-mysql.xml for connecting database. In that I want to change the database name dynamically at runtime. for example in that file having jdbc:mysql://localhost:3306/usermgmt . now I want to change the usermgmt value at dynamically.Thanks in advance.

Resources