Невозможно подключиться к MariaDB (java) - PullRequest
0 голосов
/ 28 марта 2020

Не удается подключиться к моему локальному серверу mariaDB. Кажется, все в порядке, но я получаю несколько странных исключений, когда пытаюсь получить к нему доступ. Мое единственное предположение - утверждение:

"property file 'mariadb.properties' not found in the classpath". 

Это может быть красная сельдь, но это мое лучшее предположение. В файле mariadb.jar есть файл с именем mariadb.properties, но в нем мало что есть.

Любая помощь будет очень признательна, спасибо!

public Drugs() {
    final String JDBC_DRIVER = "org.mariadb.jdbc.Driver";
    final String DB_URL = 
        "jdbc:mariadb://localhost:3306/drug_dosage";

    final String USER = "root";
    final String PASS = "XXXXXXXXXXXX";

    Connection conn = null;
    Statement stmt = null;

    try {
            Class.forName(JDBC_DRIVER);
            System.out.println("INIT\n");

            //conn = DriverManager.getConnection(DB_URL, USER, 
                //PASS);
            conn = 
                DriverManager.getConnection(
                "jdbc:mariadb://localhost:3306/drug_dosage? 
                user=root&password=XXXXXXXXXXX");
            System.out.println("CONNECTED\n");
            stmt = conn.createStatement();

            String sql = "SELECT * FROM drugs";
            ResultSet rs = stmt.executeQuery(sql);
            System.out.println("sql: " + sql + "\n");
            while (rs.next()) {
                    System.out.println("Adding: id '" + 
                        rs.getString("id") + "' drug '" + 
                        rs.getString("drug") + "'\n");
                    add(Integer.parseInt(rs.getString("id")), 
                        rs.getString("drug"));
            }
    } catch (SQLException se) {
            System.out.println("***SQL EXCEPTION***");
            se.printStackTrace();
    } catch (Exception e) {
            System.out.println("***EXCEPTION***");
            e.printStackTrace();
    }
}

Трассировка стека:

Mar 27, 2020 10:52:06 PM org.restlet.engine.connector.ServerConnectionHelper start
INFO: Starting the internal [HTTP/1.1] server on port 8182
INIT

property file 'mariadb.properties' not found in the classpath
Mar 27, 2020 10:52:10 PM org.restlet.resource.ServerResource doCatch
WARNING: Exception or error caught in server resource
Internal Server Error (500) - The server encountered an unexpected condition which prevented it from fulfilling the request
    at org.restlet.resource.ServerResource.doHandle(ServerResource.java:517)
    at org.restlet.resource.ServerResource.get(ServerResource.java:707)
    at org.restlet.resource.ServerResource.doHandle(ServerResource.java:589)
    at org.restlet.resource.ServerResource.doNegotiatedHandle(ServerResource.java:649)
    at org.restlet.resource.ServerResource.doConditionalHandle(ServerResource.java:348)
    at org.restlet.resource.ServerResource.handle(ServerResource.java:952)
    at org.restlet.resource.Finder.handle(Finder.java:246)
    at org.restlet.routing.Filter.doHandle(Filter.java:159)
    at org.restlet.routing.Filter.handle(Filter.java:206)
    at org.restlet.routing.Router.doHandle(Router.java:431)
    at org.restlet.routing.Router.handle(Router.java:648)
    at org.restlet.routing.Filter.doHandle(Filter.java:159)
    at org.restlet.routing.Filter.handle(Filter.java:206)
    at org.restlet.routing.Filter.doHandle(Filter.java:159)
    at org.restlet.routing.Filter.handle(Filter.java:206)
    at org.restlet.routing.Filter.doHandle(Filter.java:159)
    at org.restlet.engine.application.StatusFilter.doHandle(StatusFilter.java:155)
    at org.restlet.routing.Filter.handle(Filter.java:206)
    at org.restlet.routing.Filter.doHandle(Filter.java:159)
    at org.restlet.routing.Filter.handle(Filter.java:206)
    at org.restlet.engine.CompositeHelper.handle(CompositeHelper.java:211)
    at org.restlet.engine.application.ApplicationHelper.handle(ApplicationHelper.java:84)
    at org.restlet.Application.handle(Application.java:381)
    at org.restlet.routing.Filter.doHandle(Filter.java:159)
    at org.restlet.routing.Filter.handle(Filter.java:206)
    at org.restlet.routing.Router.doHandle(Router.java:431)
    at org.restlet.routing.Router.handle(Router.java:648)
    at org.restlet.routing.Filter.doHandle(Filter.java:159)
    at org.restlet.routing.Filter.handle(Filter.java:206)
    at org.restlet.routing.Router.doHandle(Router.java:431)
    at org.restlet.routing.Router.handle(Router.java:648)
    at org.restlet.routing.Filter.doHandle(Filter.java:159)
    at org.restlet.engine.application.StatusFilter.doHandle(StatusFilter.java:155)
    at org.restlet.routing.Filter.handle(Filter.java:206)
    at org.restlet.routing.Filter.doHandle(Filter.java:159)
    at org.restlet.routing.Filter.handle(Filter.java:206)
    at org.restlet.engine.CompositeHelper.handle(CompositeHelper.java:211)
    at org.restlet.Component.handle(Component.java:392)
    at org.restlet.Server.handle(Server.java:516)
    at org.restlet.engine.connector.ServerConnectionHelper.handle(ServerConnectionHelper.java:255)
    at org.restlet.engine.connector.ServerConnectionHelper.doHandleInbound(ServerConnectionHelper.java:186)
    at org.restlet.engine.connector.BaseHelper$2.run(BaseHelper.java:593)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ExceptionInInitializerError
    at org.mariadb.jdbc.internal.com.send.SendHandshakeResponsePacket.writeConnectAttributes(SendHandshakeResponsePacket.java:202)
    at org.mariadb.jdbc.internal.com.send.SendHandshakeResponsePacket.send(SendHandshakeResponsePacket.java:187)
    at org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.authenticationHandler(AbstractConnectProtocol.java:684)
    at org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.createConnection(AbstractConnectProtocol.java:546)
    at org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.connectWithoutProxy(AbstractConnectProtocol.java:1341)
    at org.mariadb.jdbc.internal.util.Utils.retrieveProxy(Utils.java:634)
    at org.mariadb.jdbc.MariaDbConnection.newConnection(MariaDbConnection.java:150)
    at org.mariadb.jdbc.Driver.connect(Driver.java:89)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:270)
    at drugs.Drugs.<init>(Drugs.java:23)
    at drugs.PlainResource.toPlain(PlainResource.java:15)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.restlet.resource.ServerResource.doHandle(ServerResource.java:506)
    ... 44 more
Caused by: java.lang.NullPointerException
    at org.mariadb.jdbc.internal.util.constant.Version.<clinit>(Version.java:84)
    ... 61 more
...