Cannot connect to database

Discussion in 'Plugin Development' started by RcExtract, Sep 23, 2017.

Thread Status:
Not open for further replies.
  1. Offline

    RcExtract

    I started my sql server. Then, when i enable my plugin, it prints an error:
    Code:
    [15:17:57 WARN]: java.sql.SQLException: No suitable driver found for localhost:3306
    [15:17:57 WARN]:        at java.sql.DriverManager.getConnection(Unknown Source)
    [15:17:57 WARN]:        at java.sql.DriverManager.getConnection(Unknown Source)
    [15:17:57 WARN]:        at com.rcextract.minecord.DatabaseManager.<init>(DatabaseManager.java:32)
    [15:17:57 WARN]:        at com.rcextract.minecord.Minecord.onEnable(Minecord.java:53)
    [15:17:57 WARN]:        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264)
    [15:17:57 WARN]:        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:337)
    [15:17:57 WARN]:        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:402)
    [15:17:57 WARN]:        at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugin(CraftServer.java:378)
    [15:17:57 WARN]:        at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugins(CraftServer.java:327)
    [15:17:57 WARN]:        at net.minecraft.server.v1_12_R1.MinecraftServer.t(MinecraftServer.java:421)
    [15:17:57 WARN]:        at net.minecraft.server.v1_12_R1.MinecraftServer.l(MinecraftServer.java:382)
    [15:17:57 WARN]:        at net.minecraft.server.v1_12_R1.MinecraftServer.a(MinecraftServer.java:337)
    [15:17:57 WARN]:        at net.minecraft.server.v1_12_R1.DedicatedServer.init(DedicatedServer.java:272)
    [15:17:57 WARN]:        at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:544)
    [15:17:57 WARN]:        at java.lang.Thread.run(Unknown Source)
    Well my sql server is started, and it is hosted on port 3306. Any ideas?
     
  2. @RcExtract
    What driver are you trying to use?

    Also, please post your code.
     
  3. Offline

    RcExtract

    @AlvinB
    Code in line 32 (line is inside constructor):
    Code:
        protected DatabaseManager() throws SQLException {
            this.connection = DriverManager.getConnection(Minecord.getHost(), Minecord.getUsername(), Minecord.getPassword());
        }
    where host is "localhost:3306"
     
  4. Online

    timtower Administrator Administrator Moderator

    @RcExtract You need to add the driver to the host
     
  5. Offline

    RcExtract

    What do u mean by adding a driver to the host? also how?
    When i install the sql server, i also installed jdbc connector.

    Edit: Thanks for helping, i solved the problem by adding "jdbc:mysql//" in front of the host. But there is still a warning:
    Code:
    [23:32:39 WARN]: Sat Sep 23 23:32:39 CST 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
    Any ideas?
     
    Last edited: Sep 23, 2017
  6. Online

    timtower Administrator Administrator Moderator

    @RcExtract That is https related I believe, don't know how to get rid of it.
     
  7. Offline

    RcExtract

    I have just googled. The warning is sent by Java, not bukkit. Besides, someone said you can prevent if by doing "jdbc:mysql://localhost:3306/database?useSSL=false but I don't think it is the best solution (I am not familiar with ssl). I may open a new thread about this topic.
     
  8. @RcExtract
    SSL is basically a way to ensure you don't get man-in-the-middled. As long as any connections you make are on trusted networks, you don't need to worry (It's also quite the hassle to get the proper certificates setup).
     
Thread Status:
Not open for further replies.

Share This Page