8

Captains Log:

Day 2 of trying to get SQL database to work with JDBC application.

I've built a try/catch method and it throws up the message that IntelliJ can't find the JDBC driver.

More research to be done. My first officer duck buddy has no input for me.

It's going to be a long day.

Comments
  • 1
    Do you use maven or add the jar to the classpath?
  • 1
    @sharktits The jar is in the WEB-INF/lib directory.

    After doing that it managed to find the jar file and it runs, but the url location isn't connecting.

    Now, I THINK the problem is with the URL, because this SQL database is hosting on a server and isn't local. But I'm not 100% sure yet.
  • 2
    @starrynights89 I'm 100% sure that you can't connect to a server that isn't even running, try the server's host name
  • 0
    @beegC0de I think you're right. I checked the url and realized that because I'm running mariadb the sql url shouldn't be there.

    jdbc:mariadb://localhost/web_student_tra...

    The connection fails as usual but it also says there's a driver conflict, so maybe I need to switch the mysql.jar with a mariadb.jar?

    Debugging, the slog we try to avoid but it comes no matter what.
  • 1
    @starrynights89 yeah I'm not sure how similar the protocols are but you should be using the mariadb one
  • 0
    @beegC0de Changed it along with the URL, still getting connection errors.

    I may have to double check my sql settings at this rate...
  • 1
    @starrynights89 can you connect to the server with another client? the mariadb client?
  • 1
    @beegC0de Everything checks out when I test the url connection. Code just won't play along. :(
  • 1
    OK. PROGRESS.

    I changed localhost to my server's IP address, and now I'm just failing to get the client to connect to the server.

    It's definitely somewhere in the sql configuration.
  • 1
    Running a query from the database shows I only have access from the localhost. That makes sense as I wanted to keep it secure but now I need to add new permissions.

    By the time I'm done with this I'll need a SQL duck in addition to my Java duck.
  • 1
    And it's fixed.

    The final result of my efforts. It was a permissions issue between the client and the server.

    Bring on that sweet sweet dopamine release brain.
  • 1
    Grats on your solve, wish I came across this thread earlier, would have helped you out. 😕
  • 1
    I guess one thing I could contribute is that (provided you are using Tomcat) you can add your db connection cradentials to context.xml in meta-inf directory, this removes the need to load the db driver manually using the 'Class.forName' as well as no longer needing to hardcode your login info. Cleans things up a lot.
  • 1
    @starrynights89 typically you wouldn't, I just noticed you were in your original post screenshot. But yeah that looks good! (There are edge cases where you may want to manually load/unload database drivers but it's extremely rare and you may never come across a need to, so for that I say using the context.xml is the way to go)
  • 1
    I should mention you may want to change your db info since you posted a pic of it.
  • 2
    May I introduce you to our lords and saviours Kotlin and HikariCP?
  • 0
    @hexc Yeah just realized that. :P I get so tired from the learning curve.
Add Comment