views:

37

answers:

2

I have a Java application and I have to connect to a MySQL DB host in aruba.it. If I make a connection, aruba.it refuses that. How to solve this?

+1  A: 

To start, I assume that you're trying to run this Java application locally, or at least at a different machine than where the MySQL DB runs and that you got a SQLException: Connection Refused.

To fix the particular problem, all routers and firewalls in the complete network pipe between the client (where the Java application runs) and the server (where the MySQL DB runs) needs to be configured to allow/forward the port number which the DB uses. This is by default 3306. If this port is blocked, you cannot reach the DB from outside.

Another solution is just to upload the Java application in flavor of a webapplication and run it by HTTP. You'd normally use JSP/Servlet for this.

BalusC
The problem is that aruba refuse all external connection.So I think that I can use a jsp page on the host of the db and I make query from my local app. to jsp page.But I don't know the way
Pippo
Step 1) write DAO class which does the task with JDBC code. Step 2) write servlet class which uses the DAO class depending on request parameters. Step 3) write JSP file with a form which calls the servlet class with specific request parameters. More hints/tutorials here: http://java.sun.com/docs/books/tutorial/jdbc/index.html, http://balusc.blogspot.com/2008/07/dao-tutorial-data-layer.html, http://courses.coreservlets.com/Course-Materials/csajsp2.html
BalusC
So can you help me to understand how make a jsp for server and the comunication betwen the jsp and my application??
Pippo
Ok I'll see thank you very much
Pippo
For the part "communication between JSP and my application", your best bet is `java.net.URLConnection`. I would however consider using a webservice (JAX-WS or JAX-RS for example) for that instead. But if you're still too green, I would play with Servlets and JSON/XML first.
BalusC
A: 

Apart from network, routers, firewall issues the reason can be that by default remote access to MySQL database server is disabled for security reasons. Mostly DB is hosted on the same server or on the trusted server. If you run java application from your desktop, you need to configure MySQL so it will accept this connections. See this manual for details how to do it.

Alexey Kalmykov
So can you help me to understand how make a jsp for server and the comunication betwen the jsp and my application??
Pippo
You have 2 options: 1) talk to your hoster, explain him that you need to connect from any pc. If you have a dedicated database (not shared between you and other clients), the hoster will suerly help you. 2) in the comments to another answer you have a few links about creating jsp
Alexey Kalmykov