0

I'm studying to be a new developer. I've rent an AWS virtual machine with Bitnami and LAMP to practice in my exercises about Java and MySQL databases.

I have a problem with the connection. I can connect to the server with SSH in the terminal but, I can`t connect with my Java programs... I try to use Jsch and I've found an example to use my Key Pair but, I don't know how I connect to the database directly with Java using the Key Pair.

Can anybody tell me a link to learn about Jsch? Does some code solution this?

Thanks for readme! That is my first question!!

  • Hello @Mol Mol, welcome to StackOverflow. your DB may be listening to another port which is not port 22 used for SSH. Default port for mysql is 3306 so maybe you should try connecting :3306/... – r4phG Nov 05 '20 at 09:05
  • You need to connect your MySQL DB with the server port. By default, MySql uses the 3306 Port number. So, if you deploy the MY SQL DB and your Java application on the same EC2 instance then you can connect your DB with localhost:3306 or if your Mysql DB is on another server then you need to connect with ip:3306 But if you are learning the AWS then I would recommend you to use the RDS. – Rishabh Rawat Nov 05 '20 at 09:24

1 Answers1

0

Thanks for the answers!! I have resolved the problem with the help of two links.

In this link, you can see how to create an SSH -L in Java. It explains all the parameters. https://ayoub.io/2016/06/29/using-jsch-for-ssh-port-forwarding-java.html

But this is not a complete solution because my code had an Exception. In this other link, you have the solution. com.jcraft.jsch.JSchException: UnknownHostKey

I hope that this helps someone.