Results 1 to 14 of 14

Thread: Java MySQL

  1. #1
    nikosa is offline Member
    Join Date
    Nov 2008
    Posts
    20
    Rep Power
    0

    Default 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...

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    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.

  3. #3
    nikosa is offline Member
    Join Date
    Nov 2008
    Posts
    20
    Rep Power
    0

    Default

    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.

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    That looks like firewall.

  5. #5
    nikosa is offline Member
    Join Date
    Nov 2008
    Posts
    20
    Rep Power
    0

    Default

    i will try to work around the firewall and i will inform you!!
    thank you for your help so far

  6. #6
    nikosa is offline Member
    Join Date
    Nov 2008
    Posts
    20
    Rep Power
    0

    Default

    mate i tried to write the same problem in mac and still getting the exact same error. any other ideas?

  7. #7
    nikosa is offline Member
    Join Date
    Nov 2008
    Posts
    20
    Rep Power
    0

    Default

    I also tried with a different database server but I am still getting the same error...

    I would really appreciate any help..

  8. #8
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    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.

  9. #9
    nikosa is offline Member
    Join Date
    Nov 2008
    Posts
    20
    Rep Power
    0

    Default

    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 much
    Last edited by nikosa; 02-05-2010 at 08:24 PM.

  10. #10
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    368
    Rep Power
    5

    Default

    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.

  11. #11
    nikosa is offline Member
    Join Date
    Nov 2008
    Posts
    20
    Rep Power
    0

    Default

    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!

  12. #12
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    368
    Rep Power
    5

    Default

    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 :)

  13. #13
    nikosa is offline Member
    Join Date
    Nov 2008
    Posts
    20
    Rep Power
    0

    Default

    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

  14. #14
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    368
    Rep Power
    5

    Default

    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

  1. Java and MySQL
    By Abder-Rahman in forum JDBC
    Replies: 6
    Last Post: 04-21-2009, 09:55 AM
  2. MySQL/JDBC Mysql query output
    By thelinuxguy in forum Advanced Java
    Replies: 4
    Last Post: 02-13-2009, 01:57 AM
  3. java programming with MySQL
    By sweet angle in forum JDBC
    Replies: 6
    Last Post: 10-29-2008, 06:14 AM
  4. java to mysql
    By thamizhisai in forum New To Java
    Replies: 12
    Last Post: 04-28-2008, 07:48 AM
  5. java to mysql
    By thamizhisai in forum Advanced Java
    Replies: 1
    Last Post: 04-26-2008, 08:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •