Connect Java-MySQL with SSH and Key Pair [duplicate] - java

This question already has answers here:
Connect to remote MySQL database through SSH using Java
(6 answers)
Closed 2 years ago.
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!!

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.

Related

Getting error while deploying Java project in Netbeans [duplicate]

This question already has answers here:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
(51 answers)
Closed 4 years ago.
I am getting an error (exceptions) while deploying my project. Some time ago the project was working but now it is not working. Please tell me a solution to get rid of this.
You dont provide any code so i ll answer about the error. Link Failure usually means that there was a problem trying to communicate with a service. This means, it seems like your jsp couldn't connect to your database on a connection level. Do you have your DB instance listening on localhost? Do you have firewalls in place that's preventing communication between your jsp and your DB instance? Have you checked the internet connection? The link? Maybe its usefull to check this Solving a "communications link failure" with JDBC and MySQL
It seems you forgot to include MySql connector into library. Please check if MySql connector is available in your project library.
As no code is provided, I just go trough troubleshooting from your GlassFish application server. I suppose you are using connection pool to connect to DB. Are you able to ping your connection pool? You might try via admin console or command line :
asadmin> ping-connection-pool myPool

Visit a server from local network [duplicate]

This question already has answers here:
How can I access my localhost from my Android device?
(44 answers)
Closed 6 years ago.
I have a pretty dumb question.
I have a Java server running on my computer, which can be visited on localhost:8080. How do I visit it through my mobile phone (in local network, connected to Wi-Fi)?
I tried to open the port or even turn off the firewall.
The path Ip address:port doesn't seem to work.
Is there something I am missing or forgot to do?
its running on your local machine not on your local network/wifi, what you'll have to do is find your computer IP and use it with the current port if you are on the same network.
in general its bad practice to test server programs like that and its highly recommended to use an Apache server and upload it to a cloud then just run it from there.

Java SSH Client (running commands and catching answers) Remote Device

I want to implement application working on Internet (I have remote Devices connected using Internet), I want to develop Java application to perform changes on remote devices....
I found this link example/code (http://twit88.com/blog/2007/12/22/java-writing-an-automated-telnet-client/) working in Telnet but is insecure I want to use SSH.
JSCH can help me (http://www.jcraft.com/jsch/)? or have you another alternative.
If you have similar code....
Thank you
JSch is be the best solution.
You can use my code snippet as an example:
https://gist.github.com/kobylinsky/1c2b21c73b68a0daa91f

How to work with RMI on the remote server? [duplicate]

This question already has answers here:
RMI cannot connect to remote server
(2 answers)
Closed 9 years ago.
I can't seem to connect 2 machines using RMI. To make sure there wasn't something wrong with my code I copied the simple example from wikipedia (http://en.wikipedia.org/wiki/Java_remote_method_invocation) and I edited the code to print out a simple int.
I tried giving all permissions and turning all the firewalls off and I still get this error:
java.rmi.ConnectException: Connection refused to host 55.229.xx.xxx; nested
exception is:java.net.ConnectException: Connection timed out: connect
I've been trying to do this for the past 3 days and I still can't seem to get past basic configuration problems.
The Problem could be your RMI server is sending back its local address, instead of WAN address.
System.setProperty("java.rmi.server.hostname", *host IP*);
also take a look at security policies regarding RMI:
http://docs.oracle.com/javase/tutorial/rmi/running.html
Check your firewall settings on your aws instance
RMI is running on 1099 port by default as i remember.

How to get all IP of a Lan Network by Java and return it into an array (Non-blocking)? [duplicate]

This question already has answers here:
How to get the list of IP addresses in a LAN?
(2 answers)
Closed 9 years ago.
Recently, I created a client/server application by java, they connect is fine, but when i test it in my school network, it can not work fine anymore, so, i need some code that return all IP of Lan network into an array so that i can put it in a JComboBox, the code should be non-blocking so it cannot hang my application.
P/S: I have been try brute-force method (like other answer) to get all IPs but it just hang my application and really not reliable.
Anyway, thank for your help.
~Best Regard and have a nice day
it can not work fine anymore, so, i need some code that return all IP
of Lan network into an array so that i can put it in a JComboBox
Why would you need these IPs????
Problem could be:
Either you bind to localhost and when you deploy in different machines you can't connect. So don't bind to localhost.
Or there is a firewall. So unblock the firewall.
Or there is no route between the machines. Can you even ping it? (but if there is a firewall it will not ping also).
So you can troubleshoot it.

Categories