Help with connection to SQL server

Discussion in 'Plugin Development' started by Airbornz, May 15, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    Airbornz

    Hello,

    So i wanted to start storing data in an sql database, the tables and everything is setup but when I try to connect im getting a no packets received from server error. My connection code is the following:
    Code:
    Connection con = DriverManager.getConnection("jdbc:mysql://mydomain.com;user=username;pass=password;database=mydatabase");
    
    String sql = "select * from distros";
                Statement sta = con.createStatement();
                ResultSet rs = sta.executeQuery(sql);
    For the connection I have also tried:

    Code:
    Connection con = DriverManager.getConnection("jdbc:mysql://mydomain.com/database","username","password");
    If someone can post actual code not just instructions that would help greatly, but instructions alone will still help. Thanks!
     
  2. Offline

    mythbusterma

    @Airbornz

    As far as I can tell, neither one of those are valid MySQL servers (I seriously doubt you own mydomain.com).

    In the event that those are just place-holders, as long as your database is set up correctly the real credentials are useless to anyone that's not on the server anyway.

    Regardless, make sure to instantiate the MySQL connector class beforehand (it has something to do with forcing class loading I believe). Paste this before you try to connect:

    Class.forName("com.mysql.jdbc.Driver").newInstance();
     
  3. Offline

    Airbornz

    @mythbusterma

    Yes that domain is a place-holder.

    Even after using the class for name it is still providing the same error.

    Is there anything else that could be causing this issue:

    Current code:
    Code:
    try {
                    Class.forName("com.mysql.jdbc.Driver").newInstance();
                } catch (InstantiationException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
    
    Connection con = DriverManager.getConnection("jdbc:mysql://mydomain.com:3306/airbornz_appidis", user, pass);
    
    String sql = "select * from distros";
                Statement sta = con.createStatement();
                ResultSet rs = sta.executeQuery(sql);
    
    Might look a bit weird because of how I pasted it from eclipse.
     
  4. Offline

    mythbusterma

    @Airbornz

    Show us the error you're getting.
     
  5. Offline

    Airbornz

    @mythbusterma
    [17:49:03 ERROR]: Error Message:Communications link failure

    The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
     
Thread Status:
Not open for further replies.

Share This Page