I am trying to connect to a remote server (my schools server to access the database) but I am not having any luck i keep getting this
SQL Exception:
State : 08S01
Message: Communications link failure
Last packet sent to the server was 0 ms ago.
Error : 0
Here is a code i found in Java, just copied to see if i can connect..
public void test()
{
try
{
// Load the database driver
Class.forName( "com.mysql.jdbc.Driver" ) ;
// Get a connection to the database
Connection conn = DriverManager.getConnection( "jdbc:mysql://my.db.url.edu;databaseName=marco;user=USERNAME;password=PASSWORD" ) ;
// Print all warnings
for( SQLWarning warn = conn.getWarnings(); warn != null; warn = warn.getNextWarning() )
{
System.out.println( "SQL Warning:" ) ;
System.out.println( "State : " + warn.getSQLState() ) ;
System.out.println( "Message: " + warn.getMessage() ) ;
System.out.println( "Error : " + warn.getErrorCode() ) ;
}
// Get a statement from the connection
Statement stmt = conn.createStatement() ;
// Execute the query
ResultSet rs = stmt.executeQuery( "SELECT * FROM Test" ) ;
// Loop through the result set
while( rs.next() )
System.out.println( rs.getString(1) ) ;
// Close the result set, statement and the connection
rs.close() ;
stmt.close() ;
conn.close() ;
}
catch( SQLException se )
{
System.out.println( "SQL Exception:" ) ;
// Loop through the SQL Exceptions
while( se != null )
{
System.out.println( "State : " + se.getSQLState() ) ;
System.out.println( "Message: " + se.getMessage() ) ;
System.out.println( "Error : " + se.getErrorCode() ) ;
se = se.getNextException() ;
}
}
catch( Exception e )
{
System.out.println( e ) ;
}
}
}
Just to complement the information, I am using Vista. What can be the issue?
Regards
There are many possible reasons why you get ‘link failure’ while connecting to your databse.
If you are sure that case 2 doesn’t apply you would have to check things on your side, switch off your antivirus/firewall software on development machine, if that doesn’t work contact the db administrator.