I am trying to connect to running Derby database from spring boot application but every time when I start my app, I can see that embedded database is starting instead of connecting to existing one. I am pretty sure my Derby database is running since java -jar $DERBY_HOME/lib/derbyrun.jar server start is executed without any error and I can connect from terminal to the database (using ij> connect 'jdbc:derby://localhost:1527/wrtschatz-db;').
I am autowiring jdbcTemplate
#Component
public class LessonItemsRetriever {
#Autowired
JdbcTemplate jdbcTemplate;
// methods doing jdbcTemplate.query(...)
}
And I expect it to create datasource from my application.yml
spring.datasource:
url: jdbc:derby://localhost:1527/wortschatz-db
username: ""
password: ""
driverClassName: org.apache.derby.jdbc.ClientDriver
But in fact, it's logging 2017-05-14 11:10:36.698 INFO 6418 --- [ main] o.s.j.d.e.EmbeddedDatabaseFactory : Starting embedded database: url='jdbc:derby:memory:testdb;create=true', username='sa' which of course results Schema 'SA' does not exist; nested exception is java.sql.SQLSyntaxErrorException: Schema 'SA' does not exist when I try to execute my queries.
What am I missing in my configuration?
Ok, I got back to my project and what I can say is that used wrong dependency. I used embedded derby while I need a client to connect to external derby db. In my build.gradle correct dependency is:
compile("org.apache.derby:derbyclient:10.13.1.1")
Related
My spring-boot app has following properties set,
spring.jpa.hibernate.ddl-auto=none
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/my-schema
spring.datasource.username=root
spring.datasource.password=*****
spring.flyway.check-location=false
spring.flyway.createSchemas=true
spring.flyway.schemas=my-schema
The schema 'my-schema' does not pre-exist and I would want for it to be created by flyway and then be used by spring-boot app to sping up HikarCP datasource.
If I run the application with the above configurations I get the following error upon startup:
Caused by: org.flywaydb.core.internal.exception.FlywaySqlException:
Unable to obtain connection from database: Unknown database 'my-schema'
Now, if I change,
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/
The application starts up perfectly and creates the schema. However, when it tries to query any table the thrown exception is:
java.sql.SQLException: No database selected
You can configure Flyway with a URL that's used purely for migrations and then configure your app to use a different URL. Something like this:
spring.flyway.url=jdbc:mysql://127.0.0.1:3306
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/my-schema
You'll also need to provide credentials for the Flyway-specific connection to the database using spring.flyway.user and spring.flyway.password.
We are using spring boot, apache camel and multiple datasources.
spring boot version: 1.5.9 release
primary database: postgres
Secondary database:oracle
We have deployed spring boot jar in linux server.
Datasource properties for postgres is
x.datasource.url=
x.datasource.username=
x.datasource.password=
x.data.jpa.repositories.enabled=true
datasource properties for oracle
y.datasource.url=
y.datasource.username=
y.datasource.password=
y.data.jpa.repositories.enabled=true
when application keeps ideal and After some times we are trying first request failed and getting error jdbc connection failed but it is working in second request without restarting.
please let me know how to keep database active.
You can use hikari connection pool. Refer to this on how to implement. You can configure no. of connections you want to keep with db
I'm creating a spring boot application using Flyway to migration and want to use a memory database for development profile, but the problem is that data is lost every time I restart application. So I need to insert some data when my application start in development profile. I tried to put a file called data.sql on src/main/resource to spring load it when application starts but it doesnt work (It didnt run the script). I tried to put INIT=runscript from 'classpath:data.sql' in the h2 url but it tries to run it before Flyway migration execution so the tables doesnt exist yet. Can anyone give me an other way to do it?
My application.yml:
spring:
datasource:
url: jdbc:h2:mem:testdb;IFEXISTS=FALSE
username: sa
password:
driver-class-name: org.h2.Driver
jpa:
show-sql: true
hibernate:
ddl-auto: none
properties:
hibernate:
dialect: org.hibernate.dialect.H2Dialect
flyway:
enabled: true
Per documentation , a profile-specific customised flyway spring.flyway.locations can be configured. The profile-specific scripts runs when that profile is active . So a dev profile configured will work on this requirement.
The initialisation script can be placed as part of migration folder which will run and populate the db.
An example can be found here
I'm trying to run my spring boot applicationon localhost ,normally i should get Whitelabel error page for the first time,but i got this error while running it.
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
Process finished with exit code 1
As shown in your log, you try to run the application without providing information about the database.
Spring and Spring-boot are not entirely based on magic.
They can guess some database information, like the url if you use an embedded datasource (as mentioned in the log you provided). Have this dependency on your classpath if you want to run your application with an in-memory database:
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
</dependency>
Make sure there is not the <scope>test</scope> in this dependency. And, at runtime, spring-boot will automatically connect to your hsqldb database.
If you are running your application and you have a production oriented database, like PostgreSQL for instance, then spring-boot can't guess what is the connection information, like the url or the database name. And you have to provide this properties in the application.properties file:
spring.datasource.url=jdbc:postgresql://<database_host>:<port>/<database_name>
spring.datasource.username=myUser
spring.datasource.password=secret
spring.datasource.type= (Not necessary)
If you don't provide that, it's like posting a mail without giving any adresses... you can't find the person you are looking for.
Hope it helps !
As the log depicts, you have to review your data-source configs, and make sure all good.
I'm trying to run a spring application that connects to an Oracle Database using hibernate. I have included the Oracle JDBC driver, specified the URL, username, password, driver-class-name, and platform.
Any help is greatly appreciated!
application.properties
spring.datasource.url=url
spring.datasource.username=username
spring.datasource.password=OCACHEUSERDEV1
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
spring.jpa.database-platform=org.hibernate.dialect.Oracle12cDialect
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
Here's a link to the JDBC driver I added to my build path.
ojdbc7
Here's the error
***************************
APPLICATION FAILED TO START
***************************
Description:
Cannot determine embedded database driver class for database type NONE
Action:
If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).