Migrating database in spring application - spring

In spring integrated hibernated application,I need to change the database from sql server to oracle without code change ?

If you really just want to change the datasource
have a look at the documentation here Spring Documentation for Oracle JDBC
You need to change your datasource that you use to point to Oracle.
Import the JDBC dependency for the Oracle JDBC connector as a dependency
Configure Hibernate to use the correct dialect
e.g. oracle.jdbc.driver.OracleDriver
Don't know how you configure your environment, but that should get you started.

Related

Spring Batch does not run when importing H2 SQL scripts

I am trying to run a Spring Batch application to create batch jobs.
My application.properties as shown below:
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:localhost;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.username=admin
spring.datasource.password=p#ssw0rd
spring.datasource.schema=schema-hsqldb.sql
The error I am getting is shown below:
Caused by: org.springframework.boot.context.properties.source.InvalidConfigurationPropertyValueException: Property spring.datasource.schema with value 'class path resource [schema-hsqldb.sql]' is invalid: The specified resource does not exist.
As far as I know, the schema-hsqldb.sql exists in classpath /org/springframework/batch/core/schema-hsqldb.sql.
The Spring boot application works when I commented out spring.datasource.schema=schema-hsqldb.sql. Do I have to manually import the SQL scripts? If so, how do I do that?
Your issue is that you are using the H2 driver with the schema of HSQL. H2 and HSQL are different products. You need to use the schema of H2 as well:
spring.datasource.schema=/org/springframework/batch/core/schema-h2.sql
That said, you don't really need to configure the datasource for embedded databases with Spring Boot, the datasource will be automatically configured. Here is an excerpt from the Embedded Database Support section of the reference docs:
Spring Boot can auto-configure embedded H2, HSQL, and Derby databases. You need not provide any connection URLs. You need only include a build dependency to the embedded database that you want to use.

Show Sql in spring jdbc applications

I'm writing a plain spring jdbc application using spring boot after a long time without using jpa or hibernate or any other ORM solution. I have need to print the runtime SQL for debugging purposes. I researched a little bit but could not find anything. I know in a jpa/hibernate application we can say following in application.properties
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
But not sure what is the name name of property in spring jdbc applications. Any help is appreciated.

Oracle 12 c RAC connection issue in jboss 4.2.3 through datasource

We were using oracle 11g, in jboss 4.2.3 using datasource xml file .It was working fine.Now we moved to oracle 12 c rac version. we changed the url in datasource xml file but it is giving [org.jboss.resource.connectionmanager.JBossManagedConnectionPool]Throwable while attempting to get a new connection: null
but using same url in jdbc connection using Class. forName(....), It is working proper.
Please help me out , why we are not able to connect through datasource xml file.
our configuration :
jboss 4.2.3
oracle 12c rac
jdk 1.6
ojdbc6.jar
Try adding a new datasource(12c one) from the JBOSS console, rather than doing this manually.

convert oracle scripts in compatible with HSQLDB

I have a spring project using Hibernate. For dev I am using oracle as a database. But for testing purpose I am using HSQLDB.
I have SQL scripts which are compatible with oracle. I want to convert those scripts compatible with HSQLDB and load the HSQLDB with those scripts to run all test cases.
If your existing tables in Oracle are generated by Hibernate , you can just simply change hibernate.dialect property to HSQLDB dialect (i.e org.hibernate.dialect.HSQLDialect ) and then set hibernate.hbm2ddl.auto to update or create . Then , Hibernate will automatically create the tables in the HSQLDB during its start-up.

JBoss 7 Spring Oracle connection pooling

I want to use Spring framework to create application that uses Oracle 11g to store data.
Can you tell me how to configure the Spring framework to use the connection pooling with JBoss 7 and Oracle 11g.
Is it possible to put this code onto OSGI bundle?
You have to configure your datascource in JBoss first. After configuring your datasource it should hava a JNDI name like "jdbc/yourDataSource".
You can now reference this datasource from your spring context.
<jee:jndi-lookup id="dataSource" jndi-name="jdbc/yourDataSource"/>
Have a look at the documentation
If you use relative JNDI names then you have to put additional settings into the web.xml. For global nameing set resource-ref="false". For Spring it should not matter what database you use as its managed by the application server.
I cannot tell you if you can use it in a OSGI bundle.

Resources