Skip to main content

Connection between mysql database and java app

Comments

19 comments

  • andrew.n
    What is the exact error it throwing?
    0
  • almir97
    " could not create connection to database server. attempted reconnect 3 times. giving up." it's one of the errors, it throws out various errors, it all depends on how I type the path to the domain, sometimes it throws out a different error. my domain is testalmo.com and the port is database 2083, how do I enter the path to the connection?
    0
  • cPRex Jurassic Moderator
    Hey there! I agree it would be good to know the error. Most applications have a database connection string where you can specify the username and password that is being used to make the connection, so testing that manually on the command line is also a good thing to try. You can use this command to test that: mysql -u username -p
    and then it will prompt you for the password for that user.
    0
  • almir97
    I list all that, and the database and username and password, so I type everything I need : conn = DriverManager.getConnection("jdbc:mysql://testalmo:2083/stalmoco_obracun", "username", "******");
    0
  • almir97
    i can't find a solution, i struggle all day but no way to fix it
    0
  • cPRex Jurassic Moderator
    That might be the issue, as port 2083 is used for cPanel but not for MySQL. If you have to specify a port in that connection string, you would want to use 3306. Can you try that instead?
    0
  • almir97
    I tried with port 3306 and without port, it will be the same problem again
    0
  • ffeingol
    Are you sure that there isn't a firewall on the cPanel server that may be blocking port 3306?
    0
  • kodeslogic
    Hey, Are you able to telnet port 3306 from your remote server?
    0
  • cPRex Jurassic Moderator
    It's possible you may not be able to use that port. If the code is running locally on the same machine you could also try "localhost" instead of a port number to see if that gives different results. If not, you may need to speak with your hosting provider or datacenter to see what they recommend and what is necessary to make that connection.
    0
  • almir97
    I discovered the problem, the problem was that my hosting was actually "web hosting", and for things like this I have to use "vps hosting", that was the problem, I did things well but I got a blockade from web hosting that didn't approve services ... do you agree that's the problem?
    0
  • cPRex Jurassic Moderator
    That isn't something we'd really be able to answer on our end as that is all controlled by your host. If they say that's how it needs to be, that's what you'll need to do to use a remote MySQL system.
    0
  • almir97
    I decided to buy vps hosting and my service says that I will not have any problems with the vps server, and they also say that the current web server is causing problems and blockages ...
    0
  • cPRex Jurassic Moderator
    That sounds good - I hope the new plan works out well for you!
    0
  • almir97
    thank you all for your help and support, if I need help I will let you know again don't worry;) ... thank you very much again!
    0
  • almir97
    hello, here I am again, i need help, i'm interested in the following: if the mysql database is on a VPS server not on the localhost server, do I have to add the Database in a Java application and create it in a Java application (Add Libary on Create database)? the picture shows the things I mean, do I have to insert and create these things on a Java application if I use a VPS server and not localhost?
    0
  • kodeslogic
    When you say "mysql database is on a VPS server" do you mean that the java application and database are on two different servers? If this is the case then you'll have to use the IP address of the VPS hosting the database instead of localhost.
    0
  • almir97
    yes, the mysql database will be on the testalmo.com domain, while the Java application is on my computer, is it enough to just use "try (Connection conn = DriverManager.getConnection (" jdbc: mysql: // vps ip .. ......... "...), that is, not to upgrade the things I asked in the first question?
    0
  • kodeslogic
    If you're able to telnet the VPS port 3306 from your localhost, then you should able to connect using "try (Connection conn = DriverManager.getConnection (" jdbc: mysql: // vps ip .. ......... "...).
    0

Please sign in to leave a comment.