2

I'm trying to connect my program to our main server but it doesn't work. when I login, this the error that happen,

Connection error:
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:
Cannot load connection class because of underlying exception:
'java.lang.NumberFormatException:For input string:"192.168.10.105"'.

here are my code, in my class where I connect it to our server's database:

package login;
import java.sql.*;
import javax.swing.JOptionPane;


public class DatabaseCls {

public Connection con;
private void conData() {
    try {

         String host = "jdbc:mysql://ipAddress:192.168.10.105/eqod-log";
        String uName = "localhost";
        String uPass= "eq0d.c0m";


        con = DriverManager.getConnection(host, uName, uPass);
    }
    catch (Exception e) {
        JOptionPane.showMessageDialog(null, e, "Connection Error", JOptionPane.ERROR_MESSAGE);
    }
}

public ResultSet rsFetch(String query) {
    ResultSet rs = null;
    try {
        conData();
        rs = con.createStatement().executeQuery(query);
        return rs;
    }
    catch(Exception e) {
        JOptionPane.showMessageDialog(null, e, "ResultSet Query Error", JOptionPane.ERROR_MESSAGE);
        return rs;
    }
}

public boolean exSQL(String query) {
    boolean done;
    try {
        done = true;
        conData();
        con.createStatement().execute(query);
        con.close();
        return done;
    }
    catch(Exception e) {
        done = false;
        JOptionPane.showMessageDialog(null, e, "Query Error", JOptionPane.ERROR_MESSAGE);
        return done;
    }
}
}

Can you help me with this, Im just new using java

kelvzy
  • 913
  • 2
  • 12
  • 19
  • 5
    Your host url shouldn't include `ipAddress:`; jdbc is parsing the url incorrectly as a result of it. Changing it to `jdbc:mysql://192.168.10.105/eqod-log` should resolve that exception. – FThompson Feb 20 '13 at 04:37
  • Error:Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from server – kelvzy Feb 20 '13 at 05:09

3 Answers3

2
    String host = "jdbc:mysql://192.168.10.105:3306/eqod-log"; //3306 is port 

Use this string as connection url. For more details JDBC URL Format

Nikhil
  • 2,857
  • 9
  • 34
  • 58
  • Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from server – kelvzy Feb 20 '13 at 05:02
  • I can't understand you. Is an exception ? – Nikhil Feb 20 '13 at 05:04
  • You may take a look at http://stackoverflow.com/questions/10567064/why-i-get-this-error-communicationslinkfailure-thelastpacketsent-when and http://serverfault.com/questions/89955/unable-to-connect-to-mysql-through-jdbc-connector-through-tomcat-or-externally – Nikhil Feb 20 '13 at 05:16
  • still no.. Im using my computer and i want to connect this to our server – kelvzy Feb 20 '13 at 05:19
  • for the settings in my.ini, I can edit it cause there instruction there are not available in my setting – kelvzy Feb 20 '13 at 05:36
  • can you post your exact exception? – Nikhil Feb 20 '13 at 05:46
1

IP address means =192.168.10.105

after the : you have to mention the port number on which the server is there by default it is on 3306, update the port number with your actual one and then try

Change this line

String host = "jdbc:mysql://192.168.10.105:3306/eqod-log";
Meherzad
  • 8,433
  • 1
  • 30
  • 40
  • Error:Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from server – kelvzy Feb 20 '13 at 05:08
  • Check your servers port number. – Meherzad Feb 20 '13 at 05:09
  • Same problem http://stackoverflow.com/questions/6865538/solving-a-communications-link-failure-with-jdbc-and-mysql – Meherzad Feb 20 '13 at 05:11
0

In this string :

"jdbc:mysql://ipAddress:192.168.10.105/eqod-log"

in URLs, the part before the colon (ipAddress) should be the IP address or the host name. Here the parser things it is a hostname "ipAddress". The part after the colon should be the port, and therefore an integer. So the parser tries to parse "192.168.10.105" as an integer, and it fails.

I think you want to use this URL instead:

"jdbc:mysql://192.168.10.105:1234/eqod-log"

With 1234 being the port (usually 3306).

Cyrille Ka
  • 15,328
  • 5
  • 38
  • 58
  • Error:Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from server – kelvzy Feb 20 '13 at 05:07