When I am retrieving data from the oracle database in the Springboot project am getting a No Datasource Set error kindly help me on this. Refer logs to sort the issue and thanks in advance.
in your application.yaml you can put sopmething like this:
spring:
datasource:
driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
url: jdbc:sqlserver://localhost:1433;databaseName=MyDatabase;encrypt=false
username: sa
password: Passw0#rd
If you are using application.properties instead of yaml then u can change to have entries like below:
spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.datasource.url=jdbc:sqlserver://localhost:1433;databaseName=MyDatabase;encrypt=false
...
note that the driver and url values will have different values depending of your database provider. The example is for SQL Server
If you are trying to connect to an Oracle XE database instance then you don't specify the driver-class-name (remove that entry) and as url you can have url: jdbc:oracle:thin:#localhost:1521:XE
Related
I have some questions regarding the datasource in my application.properties
#Data Source properties
spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/example
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
What exactly is the datasource.driver-class-name indicating?
This name refer to the classname of the JDBC driver for communicating with your database.
This class will be loaded at launch time (it must be available in the classpath).
The url is the location of your database. Here you are saying my database is located at http://localhost:3306/example where example is the database name.
The DriverClassName is the name of the JDBC driver that you use to talk to your database. in case one of the Spring data libraries like JDBC or JPA is used you can omit that property.
I am finding the following difficulties trying to configure Spring Data JPA into my Spring Boot project.
I have the following problem related to the application.properties file. This is my original application.properties file content:
spring:
application:
name: Spring Boot Excel API
datasource:
driverClassName: org.mariadb.jdbc.Driver
url: jdbc:mariadb://localhost:3306/SOC_Dashboard
username: admin
password: password
timeBetweenEvictionRunsMillis: 1000
testWhileIdle: true
validationQuery: SELECT 1
in which I configured the database connection for my project (I used JdbcTemplate to interact with my databse since now and I am replacing with Spring Data JPA).
I am not so into Spring Boot but it seems to me that exist 2 ways to set the configuration into my application.properties file: one is as done in my configuration (using something like a tree structure) and another one use a "flast" structure.
Searching online I only found this "flat" configuration for JPA:
spring.jpa.hibernate.ddl-auto=none
that is not working in my case. Putting it into my application.properties file I obtain a syntax error due to the fact that it is using the other tree style.
So I am trying to change my original file in this way:
spring:
application:
name: Spring Boot Excel API
datasource:
driverClassName: org.mariadb.jdbc.Driver
url: jdbc:mariadb://localhost:3306/SOC_Dashboard
username: admin
password: password
timeBetweenEvictionRunsMillis: 1000
testWhileIdle: true
validationQuery: SELECT 1
jpa:
hibernate:
ddl-auto: none
Is it the right way to proceed?
Another doubt is related to the ddl-auto configuration. My development is database driven. I design the DB tables and JPA entity have to map these tables. I don't want to create\modify tables starting from my entity. Is it the right configuration?
To answer your first question, YES. It is the right way of configuring spring.jpa.hibernate.ddl-auto configuration in YAML files. And the properties file which you've mention in YAML format. So, the file name should be application.yml. In spring boot, spring-boot-starter-web dependency will automatically include snakeyaml dependency to read YAML files.
For the second question, you can mention none for ddl-auto if you don't want to create tables automatically or you can simply avoid the configuration. Please refer : How does spring.jpa.hibernate.ddl-auto property exactly work in Spring?
I've got mongo DB running on docker. To set username and password I set MONGO_INITDB_DATABASE, MONGO_INITDB_ROOT_USERNAME and MONGO_INITDB_ROOT_PASSWORD variables.
And now on spring boot application a can use URI:
mongodb://username:password#host:27017/db_name?authSource=admin and it's working.
Now I want changed properties and it looks like:
spring:
data:
mongodb:
authentication-database: admin
host: host
database: db_name
password: password
port: 27107
username: username
Any ideas what is wrong?
springboot: 2.2.5
spring-boot-starter-data-mongodb-reactive
I found that on the documentation:
If you use the Mongo 3.0 Java driver, spring.data.mongodb.host and spring.data.mongodb.port are not supported. In such cases, spring.data.mongodb.uri should be used to provide all of the configuration.
So probably this is the problem and for now I just stay with the URI.
I am finishing a training project with Rest api in Java,
with springboot and a postgresql database.
Im trying to initialize the database on startup, with schema.sql, and data.sql.
The creation and the data injections works fine when i look directly in the db through PgAdmin, with that configuration file.
spring.datasource.url = jdbc:postgresql://localhost:5432/db_test
spring.datasource.username = adm_library
spring.datasource.password = admin
spring.datasource.driver-class-name = org.postgresql.Driver
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL95Dialect
#hibernate.jdbc.lob.non_contextual_creation=true
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false
spring.datasource.initialization-mode=always
#spring.jpa.hibernate.ddl-auto = none
But, if i try to use the application straight away, i'm getting
org.postgresql.util.PSQLException: ERREUR: the relation « book » doesn't exists
Here the entity causing error is "book" cause i try to retrieve books but it can be "users" if i try to retrieve users etc...
I found a way of making it work by rebooting the app without
spring.datasource.initialization-mode=always
And then it's ok.
Any explanation on this behaviour ?
Thanks !
Spring Boot automatically creates the schema of an embedded DataSource. This behavior can be customized by using the spring.datasource.initialization-mode property.
For instance, if you want to always initialize the DataSource regardless of its type:
spring.datasource.initialization-mode=always
More details can be checked in the java doc at Java-Doc and Spring Documentation.
In Spring-XD clustered environment, we are using Oracle as job repository datasource. Right now, this has been configured through servers.yml. But, we have to enable fast connection failover (FCF) for High availability (HA). Does current servers.yml support this? Or Is there a way to replace job repository data source with Oracle Pool DataSource with ONS configuration. Please advise me with any solution?
you should be able to configure your datasource like any spring datasource.
did you try configure the datasource like this http://docs.spring.io/spring-data/jdbc/docs/current/reference/html/orcl.failover.html ?
you have to include your configuration like
datasource:
url: jdbc:"jdbc:oracle:thin:#(description=(address_list=(address=(host=rac1)(protocol=tcp)(port=1521))(address=(host=rac2)(protocol=tcp)(port=1521)))(connect_data=(service_name=racdb1)))"
username: sa
password:
driverClassName: oracle.jdbc.driver.OracleDriver
validationQuery: select 1 from INFORMATION_SCHEMA.SYSTEM_USERS
fast-connection-failover-enabled:true
ONS-configuration="rac1:6200,rac2:6200"
Let me know if that works, I am curious :)