Results 1 to 12 of 12
  1. #1
    cjr9968 is offline Member
    Join Date
    Jan 2010
    Posts
    8
    Rep Power
    0

    Default Mysql and JavaFX

    I have a JavaFX application that needs access to a MySql database on a server. I have the following code that almost works:
    Java Code:
    try {
                    Class.forName("com.mysql.jdbc.Driver").newInstance();
                    sql = DriverManager.getConnection("jdbc:mysql://site/db","username","password");
                }
                catch(e:java.lang.Exception) { ExceptionBrowser.text = e.toString(); ExceptionBrowser.visible = true; }
                finally {
                        if (sql != null)
                        {
                            try
                            {
                                sql.close();
                            } catch (e:java.lang.Exception) {ExceptionBrowser.text = e.toString(); ExceptionBrowser.visible = true}
    
                        }
    
                 }
    I'm a little confused with this line:
    sql = DriverManager.getConnection("jdbc:mysql://site/db","username","password");
    As far as I know, the java application is downloaded and run locally so should "site" be replaced with a url, like "java-forums.org" for example. I've also seen it as "localhost" but this could have been for testing purposes.

    With a url I get the error:
    java.sql.SQLException: null, message from server: "Host 'computer_name' is not allowed to connect to this MySQL server"
    Could be an issue with MySQL server-side permissions.

    With localhost I get the error:
    com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:

    ** BEGIN NESTED EXCEPTION **

    java.net.ConnectException
    MESSAGE: Connection refused: connect

    Could anyone who has done this before offer me some direction?

    Thanks,
    Chris

  2. #2
    cjr9968 is offline Member
    Join Date
    Jan 2010
    Posts
    8
    Rep Power
    0

    Default More Questions!

    Sorry to post again but I thought of another question.
    I read somewhere that it is possible to decompile a Java application. If I had the MySQL database username and password hard-coded in my application would someone be able to decompile the app and get this information?
    This would be a huge security risk for the website! :eek:
    Is there some way to avoid this?

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

    Default

    You have to describe your system network configuration.

    Where is application (on end user's machine with IP given by some ISP) ?

    Where is DB (also on client or on some remote server) ?

    If DB is on remote machine you have to solve network issues.
    DB admin has to know who and how can access DB (fixed static IP's of end users,
    Virtuel Private Connection, firewall issues...)

  4. #4
    cjr9968 is offline Member
    Join Date
    Jan 2010
    Posts
    8
    Rep Power
    0

    Default

    The application is embedded in a web page on the same server as the database. I'm not planning on making the application downloadable at any point.

    :edit:
    Due to the lack of a budget, I am the database administrator, developer, deployer, website administrator, etc. so any network issues/permissions I need to deal with as well.

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

    Default

    I don't see now how can anyone decompile your code
    if you are not putting it on client?

    Client does not install your appl?

    Client does now download it?

    Client does not use any kind of
    'java web start' so he can
    hit some URL and retrieve java code to his machine?

    ...or am I missing a point?

  6. #6
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,750
    Rep Power
    19

    Default

    By embedded, do you mean it's an applet?

  7. #7
    cjr9968 is offline Member
    Join Date
    Jan 2010
    Posts
    8
    Rep Power
    0

    Default

    Quote Originally Posted by Tolls View Post
    By embedded, do you mean it's an applet?
    I'm not exactly sure how javafx is set up but I suppose it is an applet.

  8. #8
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,750
    Rep Power
    19

    Default

    Gah!
    Sorry, completely missed the JavaFX bit...:)

    If you're talking to a db on your server then you need the server address and port number that MySQL is listening on. However, at least for applets, the usual way you do this stuff is make requests to the server for data, and the server does the all the db work. I have no idea how that would work with JavaFX.

  9. #9
    cjr9968 is offline Member
    Join Date
    Jan 2010
    Posts
    8
    Rep Power
    0

    Default

    Hmm. Would it be simpler to just create a php script on the server and query that? The performance of the query doesn't need to be optimal.

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

    Default

    I'm little bit lost, what is the main problem at the moment?

    Are you reconsidering technology on client?

    Ask yourself what client must install on his PC to call your web page.

    Just browser?

    Does client need to have JRE installed, or some special runtime for JavaFX?

    Is client smart enough to install required runtime by himself, or you want to
    help him to solve that when hi hits your URL.

    Where is code for connecting on DB?
    For applets - Tolls explained

    help us to help you :)

  11. #11
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,750
    Rep Power
    19

    Default

    The client'll need JavaFX if it's a JavaFX app.

  12. #12
    cjr9968 is offline Member
    Join Date
    Jan 2010
    Posts
    8
    Rep Power
    0

    Default

    Quote Originally Posted by Tolls View Post
    If you're talking to a db on your server then you need the server address and port number that MySQL is listening on. However, at least for applets, the usual way you do this stuff is make requests to the server for data, and the server does the all the db work. I have no idea how that would work with JavaFX.
    Makes sense. I think that solved the problem. It was a server-side configuration issue that caused a connection exception. I tried the same code on a test server and changed the connection to "localhost" and it connected. :D

Similar Threads

  1. JavaFX not able to read images
    By ajeeb in forum NetBeans
    Replies: 4
    Last Post: 02-16-2010, 03:16 PM
  2. JavaFX Script and JavaFX Mobile
    By levent in forum Java Software
    Replies: 1
    Last Post: 01-27-2010, 04:48 PM
  3. how to stop/exit the mediabox JAVAFX
    By xclaim in forum New To Java
    Replies: 2
    Last Post: 11-26-2009, 02:33 AM
  4. Indentation Size Reset While Coding JavaFX
    By JDCAce in forum NetBeans
    Replies: 0
    Last Post: 10-06-2008, 09:28 PM
  5. Lobo Browser 0.98 - Now With JavaFX Support
    By lobochief in forum Java Software
    Replies: 0
    Last Post: 03-10-2008, 03:00 PM

Posting Permissions

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