Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 520375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:08:19+00:00 2026-05-13T08:08:19+00:00

/** * */ package ORM; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; /** * @author

  • 0
/**
 * 
 */
package ORM;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * @author Gwilym
 * @version 0.0
 */
public class DatabaseConnection {

 private  String userName="";
 private  String password="";
 private  String host="";
 Connection conn;

/**
  * @param userName
  * @param password
  * @param host
  */
 public DatabaseConnection(String userName, String password, String host) {
  this.userName = userName;
  this.password = password;
  this.host = host;
 }

 public DatabaseConnection(String userName, String password, String host,boolean autoConnect) {
  this.userName = userName;
  this.password = password;
  this.host = host;
  if (autoConnect)
  {
  try {
   Connect();
  } catch (DatabaseConnectionException e) {
   e.printStackTrace();
  } 
  }
 }

/**
  * @return the connection
  */
 public Connection getConn() {
  return conn;
 }

 /**
  * @param userName the userName to set
  */
 public void setUserName(String userName) {
  this.userName = userName;
 }

 /**
  * @param password the password to set
  */
 public void setPassword(String password) {
  this.password = password;
 }

 /**
  * @param host the host to set
  */
 public void setHost(String host) {
  this.host = host;
 }

/**
 * Connect, attempts to connect to the MySQL database
 * with sun JDBC 
 * & MySQL driver
 * @param none
 * @return True iff connected;
 * @return False for all else;
 * @throws DatabaseConnectionException 
 */
public boolean Connect() throws DatabaseConnectionException
{
 // Attempt to load database driver
 try
    {
        String url = "jdbc:mysql:"+host;
        System.out.println(url);
        //Load driver
        Class.forName ("com.mysql.jdbc.Driver").newInstance ();

        conn = DriverManager.getConnection (url, userName, password);
    }
 catch (ClassNotFoundException cnfe) // driver not found
 {
  conn=null;
  System.err.println ("Unable to load database driver");
  throw new DatabaseConnectionException(cnfe);
 } 
 catch(InstantiationException ie)
 {
  conn=null;
  System.err.println ("Unable to Create database driver");
  throw new DatabaseConnectionException(ie); 
 }
 catch (IllegalAccessException iae)
 {
  conn=null;
  System.err.println ("Unable to Create database driver");
  throw new DatabaseConnectionException(iae);
 } catch (SQLException sqle) {
  conn=null;
  System.err.println ("SQL error");
  throw new DatabaseConnectionException(sqle);
 }

    if (conn!=null)
    {
        System.out.println ("Database connection established"); 
        return true;
    }
    else
    {
     System.out.println ("Database connection Failed"); 
        return false;
    }

}


/**
 * Disconnects the System from the mySQL database
 * 
 * @param none
 * @return true, if successful
 * @return false if not connection in existance 
 */
public boolean Disconnect()
{
 if (conn != null)
    {
        try
        {
            conn.close ();
            conn=null;
            System.out.println ("Database connection terminated normally");
            return true;
        }
        catch (Exception e) {
       //Ignore these errors as they all result in conn.close anyway
        }
        finally
        {
        conn=null;
        System.gc();
        // my removing the refrance to conncetion all calling the Garbage collecter we insure it is destoryed.
        }
        System.out.println ("Database connection terminated with errors");
        return true;    
    }
 else
 {
  System.out.println ("No Database connection present");
        return true;    
 }
}




}

The above code is called by

DatabaseConnection db =new DatabaseConnection("USERNAME","PASSWORD","//tel2.dur.ac.uk:3306/dcs8s07_SEG",true);

for obvious reasons I have removed the user name and password , but they can be aassumed to be correct.

Right down to the problem its self I get a com.mysql.jdbc.exceptions.jdbc4.CommunicationsException when ever this code is run with the details “The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.”

My main problem at the moment is trying to discover what is actually going wrong.

In so far as I can tell the driver is being loaded correctly as my code does not throw a ClassNotFoundException, rather a SQLException of some kind.

So the problem is almost certainly the connection in some way. I can connect and query this database though a phpMyadmin located on the same server so I can assume that

1)The server is online
2)mySQL is working
3)the Username and password are correct
4) the database is present and i have the name correct

From this and “The driver has not received any packets from the server.” I am wondering if the URL malformed?

URL= jdbc:mysql://tel2.dur.ac.uk:3306/dcs8s07_SEG

or there a simple setting that is incorrect on the server whihc is not allowing me to connect?

I have pondered on this problem and attempted several googles to no avail, so any idea would be of great help

thanks in advance SO!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T08:08:20+00:00Added an answer on May 13, 2026 at 8:08 am

    This is a wrapped exception. What’s the root cause of this exception? Look further in the stacktrace.

    A very common root cause is java.net.ConnectException: Connection refused. I’ve seen this in almost 99% of the cases. If this is true in your case as well, then all the possible causes are:

    1. IP address or hostname in JDBC URL is wrong.
    2. Hostname in JDBC URL is not recognized by local DNS server.
    3. Port number is missing or wrong in JDBC URL.
    4. DB server is down.
    5. DB server doesn’t accept TCP/IP connections.
    6. Something in between Java and DB is blocking connections, e.g. a firewall or proxy.

    To solve the one or the either, follow the following advices:

    1. Verify and test them with ping.
    2. Refresh DNS or use IP address in JDBC URL instead.
    3. Verify it based on my.cnf of MySQL DB.
    4. Start it.
    5. Verify if mysqld is started without the --skip-networking option.
    6. Disable firewall and/or configure firewall/proxy to allow/forward the port.

    The username and password are irrelevant in this problem. At this point the DB can’t even be reached. You would have gotten a “Login failed” or “Not authorized” SQLException otherwise.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got following java class. package com.org.data.dbresource; import org.springframework.orm.ibatis.SqlMapClientTemplate; public class DBConnectionManager { private
package src; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Command { public static
package test; import java.awt.*; import java.awt.event.*; import java.awt.geom.Ellipse2D; import java.awt.image.BufferedImage; import javax.swing.*; public class
package GC; import java.util.Scanner; public class main { public static void main(String args[]) {
package { import mx.controls.LinkButton; import flash.text.TextLineMetrics; public class multiLineLinkButton extends LinkButton { override protected
package mp1practice; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.logging.Level;
package pack; public class sample{ public static void main(String input[]) { NumberFormat numberFormat =
package org.study.algos; public class Study { public static void main(String[] args) { A a
package nidhin.survey; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.content.ContentValues; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper;
I have an ORM class called Person, which wraps around a person table: After

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.