I'm trying to integrate Amazon RDS with webapp developed in Spring MVC. I'm using Flyway as db migration tool. I'm able to connect to the RDS but the thing is whenever flyway starts the migration, it tries to create schema_version table without firing use database_name query.
And that's where RDS throws error saying "No Database Selected".
I tried setting schema for flyway, flyway.setSchemas("koomi");, but no help, its still giving same error.
So is there any way by which we can make flyway to execute use database_name query before it fires query for schema_version?
Put the database name in the url and you should be ok
Related
I was asked this question by a colleague, and I am unable to answer it:
I have an in memory database (h2), and I have a SQL database server which our app needs to talk too. But due to the two different SQL dialects we are now wondering how do we get around the issue by doing the least amount of work?
This to be done in spring boot. I am aware of how to connect to the h2 database and SQL database server, but I am unsure on the rest.
If everything is setup by Spring, you should not be worried about the 2 different SQL dialects. Just be sure that spring.jpa.database is set to default to let Spring autodetect the right dialect for each datasource.
Here's a link that explain how to use/initialize two datasource in a Spring Boot projet if you need some more information.
I planned to use ExampleDS (java:jboss/datasources/ExampleDS) for Java development before going to production. It is the default data source in Wildfly, configured using the embedded H2 database for developer convenience. I need to see the data in these tables during development. I am developing in IntelliJ. There is a ”database” tab to the upper right. I have previously added databases here and I could see their content. But I don’t know how to add the ExampleDS database.
I then tried this approach instead:
1) Deploy a prebuilt WAR-file for H2 Console: https://www.cs.hs-rm.de/~knauf/JavaEE6/kuchen/H2Console.war )
2) Open URL http://localhost:8080/H2Console/h2
3) login with username/password = "sa"
I could then access the H2 console. It was however impossible to login with the default JDBC URL
java:jboss/datasources/ExampleDS
I tried with name and password sa, but it always says "wrong password".
So I read the documentation on
https://developers.redhat.com/quickstarts/eap/h2-console/
It says:
To access the test database that the greeter quickstart uses, enter these details:
JDBC URL: jdbc:h2:mem:greeter-quickstart;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1
User Name: sa
Password: sa
So I tried that and I could finally connect. But there seems to be no tables in the database. The documentation says:
Take a look at the data added by the greeter application. Run the following SQL command:
select * from users;
I tried that, but got the message
Table "USERS" not found
The tables that I have created in my JPA app can also not be found. I assume that is because my persistance file points to
java:jboss/datasources/ExampleDS
So I changed it to
jdbc:h2:mem:greeter-quickstart;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1
Then I got this error when trying to run my JPA app from IntelliJ:
"WFLYCTL0412: Required services that are not installed:" => ["jboss.naming.context.java.jdbc:h2:mem:greeter-quickstart;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1"],
"WFLYCTL0180: Services with missing/unavailable dependencies" => [
Does anypne know how I should proceed with this to actually add my tables to a H2 database and then to see the data in these tables?
I think you don't have some of the concepts clear:
H2 has several options to create a database, using a file as basis or in-memory.
The in-memory is not stored in any place, for this reason if you configure it in your app like this:
jdbc:h2:mem:whatever
The jvm starts a database in their own memory, only available for the vm.
If you want to connect from outside I recommend to use the embedded or server mode.
Ofc an in-memory database will be empty, you have to populate it in start-up.
I used it a lot for testing. It's pretty cool.
Check the H2 cheatsheet:
https://www.h2database.com/html/cheatSheet.html
I'm trying to connect a spring boot java application to an Oracle database. Oracle SQL Developer shows the tables I wish to query being in the DB named testdb under Other users -> `testUser.
I can connect to the DB using url jdbc:oracle:thin:#localhost:1521:testdb. However, when I use an SQL statement
SELECT * FROM SCHEMA_DEFINITION WHERE SCHEMA_NM = ?
Java doesn't find the table named SCHEMA_DEFINITION. Using testUser.SCHEMA_DEFINITION in the SQL statement does work. How can I tell Java to look for all the tables in Other users->testUser?
I have tried setting the datasource's schema (dataSource.setSchema("testUser");) and changing the url (adding ?search_path=testUser and ?currentSchema=testUser).
None of these work.
it's not a java issue, what you need is to log into the user testUser so you can query those tables without the verbose syntax if you really need to keep these queries as is, and run them from testdb then you need to create synonyms for those tables inside testdb schema:
CREATE SYNONYM TESTDB.SCHEMA_DEFINITION FOR testUser.SCHEMA_DEFINITION;
do this for each table and they will work.
Found the solution in github.com/embulk/embulk-input-jdbc/issues/144. dataSource.setSchema("testUser"); works if I use ojdbc7 (I was using ojdbc6 in my pom.xml).
I created a small POC app with spring boot, using hibernate (5.2.9) and maria db (10.1.19).
I had some sql dialect issues where my create/drop table SQL was using type=MyIasam but resolved that locally by setting the spring.jpa.properties.hibernate.dialect, however, when I deploy to the cloud (PCF) all of the cloud profile stuff kicks in, and I end up with hibernate deciding its dialect is going to be org.hibernate.dialect.MySQLDialect
this results in invalid SQL getting generated for creating new tables.
Note that I'm not really sure what else could be happening. This is a spring boot app (1.5.3) and the cloud profile is kicking in to do auto configuration. There's a bunch of properties injected. And I can't seem to get my dialect property to be respected.
This is a solid crushingly easy problem that is the escaping me.
Any ideas what I need to set, or provide as dependencies?
I tried removing all of the mysql dependencies, but then the connection string inject is jdbc:mysql... which i think may be part of the problem...
I'm trying to get and write data to Mysql Db using Spring Boot & Vaadin. I'm new in Spring and it's too boringly to make simple web project with all of Spring's configurations. So I decided to use Spring Boot. And now my headache is - getting and writing data to Mysql Db. I wrote in application.properties configuration for DB, also "spring.jpa.hibernate.ddl-auto=create" create new table in db (if it's not exists), but no data loaded and no data added to db table. As I see from this doc https://docs.spring.io/spring-boot/docs/current/reference/html/howto-database-initialization.html there is no need to write from beginning some classes to connecting db and getting data...
Please help. https://github.com/AntonKostyukewicz/VaadinCrud - here is my sources of project.
Have you looked at the Vaadin JPA Container add-on? If you are willing to talk to the DB in JPA, that's an excellent option. https://vaadin.com/docs/-/part/framework/jpacontainer/jpacontainer-overview.html