Łączenie się z bazą danych w Intellij Idea

0

Witam!
Działałem sobie jakiś czas w Intellij. Wszystko szło dobrze, aż do momentu.. baz danych. Przejrzałem wiele stron, poradników lecz dalej nic.
Moim celem jest tylko i wyłącznie połączenie się z bazą danych.

Mam następujący kod:

import java.sql.Connection;
import java.sql.SQLException;

public class Aplikacja {

    public static void main(String[] args) {
        Connection connection = null;

        try {
            connection = ConnectionConfiguration.getConnection();
            if (connection != null)
            {
                System.out.println("Jest połączenie");

            }


        } catch (Exception e) {

            e.printStackTrace();
        } finally {
            if (connection != null)
            {
        try {
            connection.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
            }
        }

    }
}


oraz

import java.sql.Connection;
        import java.sql.DriverManager;

public class ConnectionConfiguration {

    public static Connection getConnection(){

        Connection connection = null;


        try {
            Class.forName( "com.mysql.jdbc.Driver" );
            connection = DriverManager.getConnection( "jdbs.mysql://localhost:3306/test", "root", "" );

        } catch (Exception e) {
            e.printStackTrace();
        }
        return connection;
    }
}

Mam sterownik, lecz dalej nic. Wyskakuje mi błąd:

Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
java.sql.SQLNonTransientConnectionException: Cannot load connection class because of underlying exception: com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, failed to parse the main URL sections.
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:108)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:95)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:87)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:61)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:71)
	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:79)
	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:131)
	at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:231)
	at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:677)
	at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:228)
	at ConnectionConfiguration.getConnection(ConnectionConfiguration.java:13)
	at App.main(App.java:10)
Caused by: com.mysql.cj.exceptions.UnableToConnectException: Cannot load connection class because of underlying exception: com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, failed to parse the main URL sections.
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488)
	at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:59)
	at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:103)
	... 5 more
Caused by: com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, failed to parse the main URL sections.
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488)
	at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:59)
	at com.mysql.cj.conf.ConnectionUrlParser.parseConnectionString(ConnectionUrlParser.java:139)
	at com.mysql.cj.conf.ConnectionUrlParser.<init>(ConnectionUrlParser.java:129)
	at com.mysql.cj.conf.ConnectionUrlParser.parseConnectionString(ConnectionUrlParser.java:118)
	at com.mysql.cj.conf.ConnectionUrl.getConnectionUrlInstance(ConnectionUrl.java:179)
	at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:201)
	... 4 more

Czy to może być błąd w odnalezieniu sterownika?

0

Przecież masz napisane co masz załączyć :D

Linijkę Class.forName( "com.mysql.jdbc.Driver" );
Masz zmienić na Class.forName( "com.mysql.cj.jdbc.Driver" );

0

: Malformed database URL, failed to parse the main URL sections.
źle przeklepałeś i kilka znaków się nie zgadzało
connection = DriverManager.getConnection( "jdbc:mysql://localhost:3306/test", "root", "" );

0

Dzięki za odpowiedzi!
Przy poprawieniu błędów pojawił mi się kolejny błąd:

java.sql.SQLException: The server time zone value 'Ârodkowoeuropejski czas letn' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.

Pojawił mi się błąd taki jak przy poprzedniej próbie, szukałem na forum, (ten wątek), lecz to było zwiazane z używaniem daty. Na innym forum znalazłem podpowiedź, aby zmienić na wcześniejszą wersję sterownika. Mieliście może już taki problem?

1 użytkowników online, w tym zalogowanych: 0, gości: 1