简体   繁体   中英

Deploying app in aws throws error java.sql.SQLException: No database selected

Good day developers , im working in this Angular+MySQL+Spring-Boot app, and i'm in that phase of exporting my database to AWS, but for any reason after having tested the database connection to my mySQL Workbench , when i set the parameters in the application.properties the error java.sql.SQLException: No database selected appears.

The endpoint AWS throws as well as the port are :

endpoint: bookingrestaurantok.clnhc7kmwszz.us-west-2.rds.amazonaws.com

port: 3306

thus using this elements on my app.properties i just initialize



spring.datasource.url=jdbc:mysql://bookingrestaurantok.clnhc7kmwszz.us-west-2.rds.amazonaws.com
:3306/restaurant_booking_ok?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC

spring.datasource.username=ssssssssssss
spring.datasource.password=sssssssssssssss

spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect

logging.level.org.hibernate.SQL=debug

I'm exposing here the workbench database and its endpoint

在此处输入图片说明

在此处输入图片说明

But any time i try to reach whichever the endpoints in my app the error 500 of no database selected shows up. Could you help me to see what step im ommiting

I know is a lot of code but also i attach my pom in case you detect something is wrong there


<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.2.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>cubancoder</groupId>
    <artifactId>restaurant-booking</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>restaurant-booking</name>
    <description>Demo project for Spring Boot made on maven  front end angular</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-jpa -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.18</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.modelmapper/modelmapper -->
        <dependency>
            <groupId>org.modelmapper</groupId>
            <artifactId>modelmapper</artifactId>
            <version>2.3.8</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>


        <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-mail 
            dependencia para el envio de emails -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
            <version>2.3.3.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- https://mvnrepository.com/artifact/junit/junit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13</version>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.mockito/mockito-all -->
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>1.10.19</version>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.mockito/mockito-core -->
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>3.4.6</version>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.stripe/stripe-java dependencia para el wireling de pagos
        y demas-->
        <dependency>
            <groupId>com.stripe</groupId>
            <artifactId>stripe-java</artifactId>
            <version>19.45.0</version>
        </dependency>



    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

Thanks in advance for your help

The error ava.sql.SQLException: No database selected seems to refer to the database name.

The database name is set correctly in the property spring.datasource.url , however for Amazon RDS databases is enough to point that property to the endpoint (without the database name). Try the following:

spring.datasource.url=jdbc:mysql://bookingrestaurantok.clnhc7kmwszz.us-west-2.rds.amazonaws.com
:3306

Edit:

I was able to reproduce the error. The issue is that Amazon RDS by default creates a new database instance but not a database. To create a database there is this option to set:

在此处输入图片说明

Also the errors does not appear after connecting to the database, but only after the first query (for example creating a new table).

Setting "Initial database name" to mydb and having a database instance id database-instance-1 , then the url would be:

spring.datasource.url=jdbc:mysql://database-instance-1.blablabla.rds.amazonaws.com:3306/mydb

I know that your spring.datasource.url looks correct and you can see your database in Workbench but I suggest you to create a new database instance using the Amazon RDS dashboard and setting the database name as explained above.

It's not a definitive answer but I hope this tentative will let you to figure out the cause of the issue.

  1. Please check the connectivity between the node in which application is deployed and the instance in which DB is there.
  2. Have you provided enough permissions for both nodes for communications ?.
  3. Do ping from application machine to db machine.
  4. Install mysql client in application machine and try to connect to the db.
  5. Is the database available in that database server ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM