Results 1 to 14 of 14
Thread: Java MySQL
- 02-05-2010, 07:07 PM #1
Member
- Join Date
- Nov 2008
- Posts
- 20
- Rep Power
- 0
Java MySQL
Hello Guys,
I have a problem that initially seemed to be pretty easy to overpass so I said OK, I will give it a try another time but I finally end up unable to solve it.
The story is simple:
I have a java app that has to talk to an external mysql server. Currently everything is working smoothly because i run the program in localhost mode. Now I have to pass the java app to the user and I have to copy the db schema to an external mysql server.
Nothing seems to work right now.
I heard that it is impossible to connect my java app to an external mysql db if the user does not have a static ip. is there any way I can work around this problem?
If you need additional info please don't hesitate...
- 02-05-2010, 07:10 PM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
No, it's not impossible. Somewhat discouraged, but definately not impossible. See the User Management portion of the MySQL Manual, paying especial attention to the "GRANT" statement information and the "%" symbol.
- 02-05-2010, 07:15 PM #3
Member
- Join Date
- Nov 2008
- Posts
- 20
- Rep Power
- 0
The code I am writing to connect to mυ database is:
String driverName = "org.gjt.mm.mysql.Driver" (or "com.mysql.jdbc.Driver"); // MySQL JDBC driver
Class.forName(driverName).newInstance();
// Create a connection to the database
String serverName = "sql307.podserver.info"; //this is server info
String mydatabase = "(My DB Name)";
String url = "jdbc:mysql://" + serverName + "/" + mydatabase; // a JDBC url
String username = "(My Username)";
String password = "(My password)";
connection = DriverManager.getConnection(url, username, password);
System.out.print("OK so far");
Statement stmtRO = connection.createStatement(ResultSet.TYPE_SCROLL_I NSENSITIVE,ResultSet.CONCUR_READ_ONLY);
String query = "SELECT * FROM User WHERE Email = 'nick@abc.com'";
ResultSet rs = stmtRO.executeQuery(query);
if(rs != null)
System.out.print("Yes");
else
System.out.print("No");
but after a while i get the error:
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.net.ConnectException
MESSAGE: Connection timed out: connect
STACKTRACE:
java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl .java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSoc ketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.j ava:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.j ava:366)
at java.net.Socket.connect(Socket.java:519)
at java.net.Socket.connect(Socket.java:469)
at java.net.Socket.<init>(Socket.java:366)
at java.net.Socket.<init>(Socket.java:209)
at com.mysql.jdbc.StandardSocketFactory.connect(Stand ardSocketFactory.java:256)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:271)
at com.mysql.jdbc.Connection.createNewIO(Connection.j ava:2771)
at com.mysql.jdbc.Connection.<init>(Connection.java:1 555)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonReg isteringDriver.java:285)
at java.sql.DriverManager.getConnection(DriverManager .java:582)
at java.sql.DriverManager.getConnection(DriverManager .java:185)
at Arts_MySQL.main(Arts_MySQL.java:25)
** END NESTED EXCEPTION **
Last packet sent to the server was 0 ms ago.
at com.mysql.jdbc.Connection.createNewIO(Connection.j ava:2847)
at com.mysql.jdbc.Connection.<init>(Connection.java:1 555)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonReg isteringDriver.java:285)
at java.sql.DriverManager.getConnection(DriverManager .java:582)
at java.sql.DriverManager.getConnection(DriverManager .java:185)
at Arts_MySQL.main(Arts_MySQL.java:25)
I cannot even reach the first print message.
I would really appreciate your help.
- 02-05-2010, 07:18 PM #4
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
That looks like firewall.
- 02-05-2010, 07:29 PM #5
Member
- Join Date
- Nov 2008
- Posts
- 20
- Rep Power
- 0
i will try to work around the firewall and i will inform you!!
thank you for your help so far
- 02-05-2010, 07:41 PM #6
Member
- Join Date
- Nov 2008
- Posts
- 20
- Rep Power
- 0
mate i tried to write the same problem in mac and still getting the exact same error. any other ideas?
- 02-05-2010, 07:54 PM #7
Member
- Join Date
- Nov 2008
- Posts
- 20
- Rep Power
- 0
I also tried with a different database server but I am still getting the same error...
I would really appreciate any help..
- 02-05-2010, 08:01 PM #8
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Why do you think a MAC would be unaffected by a firewall?
It is a firewall. It could be caused by a client firewall not allowing outgoing connections and/or a server firewall not allowing incoming connections, or a fiewall on a proxy server/gateway somewhere in the middle that is disallowing incoming and/or outgoing connections.
None of your "tests" has "disproved" the possibility of it being a firewall. They have only served to bolster the possibility of it being a firewall on the server or on a proxy/gateway.
- 02-05-2010, 08:10 PM #9
Member
- Join Date
- Nov 2008
- Posts
- 20
- Rep Power
- 0
I tried with mac in order to ensure that my antivirus will not cause any problem instead of firewall.
It might be heard stupid but my mac has an option to:
"allow all incoming connections" but nothing changed so far.
Can you please help me as to if there are any other options for me to change before I contact them?
Thank you very muchLast edited by nikosa; 02-05-2010 at 08:24 PM.
- 02-05-2010, 09:33 PM #10
Senior Member
- Join Date
- Dec 2009
- Location
- Belgrade, Serbia
- Posts
- 364
- Rep Power
- 4
First you have to describe here complete network configuration of client and server where mysql is now.
there are ways to connect on machine with dynamic IP
For beginning read this article to get idea
How can I connect to my home computer from work?
If it does not ring a bell post your network schema in detail
so we can discuss it.
- 02-06-2010, 01:12 PM #11
Member
- Join Date
- Nov 2008
- Posts
- 20
- Rep Power
- 0
Hello FON,
As I am new in programming I don't know exactly what you are asking me to post so I will try to give as many info as I can to get the idea..
I have an apache server in my windown xp pc and I am connecting my java app to it with no problem (localhost). Now is the time that I have to move the db schema to an online db and use it with my client java app. I decided to work with a free web host provider that provides mysql databases. I export the db to the new server successfully I went to change the db connection in order to connect to the remote mysql. And the above problems started there.
As for the architecture I have a 2 tier fat client - server application. Nothing special because I am making my first steps and I do not know many things about web services and middle-wares.
As for the server configuration can you please explain me what do you want me to tell you specifically.
Thank you very very much!
- 02-06-2010, 03:15 PM #12
Senior Member
- Join Date
- Dec 2009
- Location
- Belgrade, Serbia
- Posts
- 364
- Rep Power
- 4
So you moved db from local machine to some provider's server.
And what about apache? I don't get it?
Have you moved your web app from local apache to remote provider's apache??
If you have then everything is on provider's side.
In provider's own network there are now 2 servers one is apache and other mysql.
If you connect to DB from some java class on that apache i cannot see problem, provider always set those 2 servers so they can communicate.
But if you connect from java class on apache that is on your own home PC
to remote provider's mysql DB that is totally different situation.
In this case you are in one part of network administrated from your ISP
that probably gives you some dynamic IP, and that mysql DB server is in
some intranet of that free web hosting company, but they have to protect it in some way,
so i don't know if that mysql has some static IP and is configured so someone from outside can reach it.
I don't know if this helped you,
but be sure you have to deal with this stuff sooner or later on every project
so take your time and we will help you solve it :)
- 02-06-2010, 06:18 PM #13
Member
- Join Date
- Nov 2008
- Posts
- 20
- Rep Power
- 0
You are right. When I said apache I meant the suit that makes your computer a server. (Apache, PHP, MySQL..). I copied the MySQL schema to my online MySQL but the java application resides on the client machine (say, my machine). Now I am trying to connect to the online db from the client machine. Is this possible with a dynamic ip. I see that there are security issues raised here but for the sake of my first completed java application that talks to an online db it will be ok. I am not going to store any private info on this db so I don't really care.
PS. Is there a way to copy the java application in an online directory and run the jar that will use localhost connection to the db. Is it possible or it is completely nonsense! I know that the java application has to be compiled on the client's operating system and I didn't even try it.
Thank you very much for your help so far!
Nick
- 02-07-2010, 02:17 AM #14
Senior Member
- Join Date
- Dec 2009
- Location
- Belgrade, Serbia
- Posts
- 364
- Rep Power
- 4
This is what I found after trying to connect from home machine
to mysql DB at free hosting provider:
"Free hosting accounts do not have remote MySQL access." :(
And i was hoping that this was possible because I found that
this guys offers in Cpanel GUI for managing your free account:
"Remote Database Access Hosts" option with this text:
"You can allow external web servers to access your MySQL databases by adding their domain name to the list of hosts that are able to access databases on your web site."
So go ahead and send them a mail.
If it is possible they will send you some example how to do it.
TIP:
Whatever you do with this free hosting solutions
be sure your home firewall does not blocking your work
cheers!
Similar Threads
-
Java and MySQL
By Abder-Rahman in forum JDBCReplies: 6Last Post: 04-21-2009, 09:55 AM -
MySQL/JDBC Mysql query output
By thelinuxguy in forum Advanced JavaReplies: 4Last Post: 02-13-2009, 01:57 AM -
java programming with MySQL
By sweet angle in forum JDBCReplies: 6Last Post: 10-29-2008, 06:14 AM -
java to mysql
By thamizhisai in forum New To JavaReplies: 12Last Post: 04-28-2008, 07:48 AM -
java to mysql
By thamizhisai in forum Advanced JavaReplies: 1Last Post: 04-26-2008, 08:21 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks