SOLVED Connection between mysql database and java app

almir97

Member
Dec 10, 2020
10
1
3
Bosna i Hercegovina
cPanel Access Level
Website Owner
Hello,

I have a problem connecting the connection mysql database on cPanel, I created on the online domain and cpanel mysql database, the required table, I set % on Remote MySQL, everything is done properly but I can not connect Java application(NetBeans) with the required database, constantly throwing out some errors, exceptions, etc...

Can anyone help me?
 

almir97

Member
Dec 10, 2020
10
1
3
Bosna i Hercegovina
cPanel Access Level
Website Owner
" 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?
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
14,359
2,249
363
cPanel Access Level
Root Administrator
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:

Code:
mysql -u username -p
and then it will prompt you for the password for that user.
 

almir97

Member
Dec 10, 2020
10
1
3
Bosna i Hercegovina
cPanel Access Level
Website Owner
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", "******");
 

kodeslogic

Well-Known Member
PartnerNOC
Apr 26, 2020
549
255
138
IN
cPanel Access Level
Root Administrator
Hey,

Are you able to telnet port 3306 from your remote server?
 
  • Like
Reactions: cPRex

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
14,359
2,249
363
cPanel Access Level
Root Administrator
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.
 

almir97

Member
Dec 10, 2020
10
1
3
Bosna i Hercegovina
cPanel Access Level
Website Owner
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?
 

almir97

Member
Dec 10, 2020
10
1
3
Bosna i Hercegovina
cPanel Access Level
Website Owner
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?
 

Attachments

kodeslogic

Well-Known Member
PartnerNOC
Apr 26, 2020
549
255
138
IN
cPanel Access Level
Root Administrator
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.
 

almir97

Member
Dec 10, 2020
10
1
3
Bosna i Hercegovina
cPanel Access Level
Website Owner
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?
 

kodeslogic

Well-Known Member
PartnerNOC
Apr 26, 2020
549
255
138
IN
cPanel Access Level
Root Administrator
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 .. ......... "...).
 
  • Like
Reactions: cPRex