My idea is like this: The provider does not allow external mysql requests. I have been searching for hours for a solution to connect local java with remote server java. The remote java server would then make the mysql request and send it back. Any ideas/Links for me?
1 Answers
You could do this with port forwarding, you can use ssh to setup a tunnel. So there is no need to write a java server program.
The last link have an example of your exact problem, though it is connecting to a PostgreSQL database, I translated that info to MySQL below.
An example here is when you need to connect to a database console, which only allows local connection for security reasons. Let’s say you’re running MySQL on your server, which by default listens on the port 3306.
$ ssh -L 9000:localhost:3306 user@example.com
The part that changed here is the localhost:3306, which says to forward connections from your local port 9000 to localhost:3306 on your server. Now we can simply connect to our database.
$ mysql -h localhost -p 9000
You should now be able connect your local java jdbc program with the url jdbc:mysql://localhost:9000/dbname
and it will be tunneled to the remote database which would see your tunneled connection as a local connection.
Connection c = DriverManager.getConnection("jdbc:mysql://localhost:9000/dbname","username", "password");

- 1,959
- 13
- 20
-
oh ye i forgot to written.... the problem is, the DB is on a free webspace provider, that i want use for test my apps. so i cant make changes in the db-console – Newbster Apr 09 '16 at 13:19
-
The last paragraph is about how to connect from java. I will update answer to make that more clear – gustf Apr 09 '16 at 13:23
-
thx for this answer. Maybe better explain with the name of provider. This kind https://www.bplaced.net/ dont allowed this extern conenction. Extern means "Connection c = DriverManager.getConnection("jdbc:mysql://username.bplaced.net:3603/dbname","username", "password");" Its not working. I found a other provider now, but anyway. if not to many work for you, woul be interesting, how work arround, because the provider sayed me, if the java file is on the server than it works with this localhost, but if not-how than? (sorry for bad english grammar. I hope you can understand) – Newbster Apr 09 '16 at 13:27
-
Ok, you are not allowed to do port-forwarding on the host i guess. Are you allowed to have a java program on the server? Looks like its only php on the site? – gustf Apr 09 '16 at 13:34
-
i am not sure. i am a java newbie sry. I have FTP-informations for login , thats all i can say ;( – Newbster Apr 09 '16 at 13:36
-
Ok, no problem. From the site it seems like its PHP only, then you probably have to write some php code on the web-server that actually does the database connections. and let you java program communicate to that through http. – gustf Apr 09 '16 at 13:44