Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Connect a desktop application to a MySQL Database that's hosted on the cloud

  1. #1
    Junior Member
    Join Date
    Dec 2017
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Connect a desktop application to a MySQL Database that's hosted on the cloud

    Hi everyone,
    I’m building a desktop application using Java and a MySQL Database. The MySQL database is hosted on HostGator cloud server.
    I wrote the following code for database connection, but it isn't working.

    public static Connection Connerdb()
    {
    try
    {
        Class.forName("com.mysql.jdbc.Driver");
        Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/TestDB",root, " " );
        return con;
    }
    catch (ClassNotFoundException | SQLException e){
        JOptionPane.showMessageDialog(null, e);
        return null;
    }   
    }
    Note: in the code, i changed localhost to the server Host Name and the 3306 to the server port number
    Last edited by Manar01; December 25th, 2017 at 02:32 PM.

  2. #2
    Junior Member
    Join Date
    Dec 2017
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Connect a desktop application to a MySQL Database that's hosted on the cloud

    Hi everyone,
    I’m building a desktop application using Java and a MySQL Database. The MySQL database is hosted on HostGator cloud server.
    I wrote the following code for database connection, but it isn't working.

    public static Connection Connerdb()
    {
    try
    {
        Class.forName("com.mysql.jdbc.Driver");
        Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/TestDB",root, " " );
        return con;
    }
    catch (ClassNotFoundException | SQLException e){
        JOptionPane.showMessageDialog(null, e);
        return null;
    }   
    }
    Note: in the code, i changed localhost to the server Host Name and the 3306 to the server port number

    when i run the desktop app, this message is shown:
    Connect java app to mysql on cloud.jpg

  3. #3
    Junior Member
    Join Date
    Dec 2017
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Connect a desktop application to a MySQL Database that's hosted on the cloud

    it's solved, the port number must be 3306

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Connect a desktop application to a MySQL Database that's hosted on the cloud

    Can you copy the contents of the console and paste it here as text?
    The contents of the posted image is not readable.

    Note: Also call the printStackTrace method in the catch block to get all of any error message
    If you don't understand my answer, don't ignore it, ask a question.

  5. The Following User Says Thank You to Norm For This Useful Post:

    Manar01 (December 25th, 2017)

  6. #5
    Junior Member
    Join Date
    Dec 2017
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Smile Re: Connect a desktop application to a MySQL Database that's hosted on the cloud

    Thanks for help.
    The problem has been resolved.

Similar Threads

  1. How to connect or create database by using mysql to java
    By hafiz013 in forum Java Theory & Questions
    Replies: 4
    Last Post: January 3rd, 2013, 04:28 AM
  2. Replies: 1
    Last Post: December 21st, 2012, 10:35 AM
  3. Connect to MySQL database on remote IP/port through JDBC
    By javauser in forum JDBC & Databases
    Replies: 6
    Last Post: September 7th, 2012, 02:11 AM
  4. connect to mysql database
    By aueddonline in forum JDBC & Databases
    Replies: 5
    Last Post: December 17th, 2011, 02:44 PM
  5. Desktop Database Application
    By TCoomer in forum JDBC & Databases
    Replies: 2
    Last Post: June 4th, 2009, 03:51 PM

Tags for this Thread