Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. Database Connection from Java

Database Connection from Java

Scheduled Pinned Locked Moved Java
databasejavamysqlcomhelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    prithaa
    wrote on last edited by
    #1

    Hello, I am trying to connect to mysql from Java with the following but getting this error Exception in thread "main" Communications link failure

    package testPackage;

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.util.Properties;

    public class Main {

    public static void main(String\[\] args) throws Exception {
    	// TODO Auto-generated method stub
    			  
    	    try {
    	      Class.forName("com.mysql.jdbc.Driver");
    	      Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/student?useSSL=true","root","success");  
    	      System.out.print("Database is connected !");
    		  con.close();				
    }
    	    catch(Exception e)
    	    {
    	    	System.out.println(e.getMessage());
    	    	throw e;
    	    }
    	    	
    	    }
    

    }

    L 1 Reply Last reply
    0
    • P prithaa

      Hello, I am trying to connect to mysql from Java with the following but getting this error Exception in thread "main" Communications link failure

      package testPackage;

      import java.sql.Connection;
      import java.sql.DriverManager;
      import java.util.Properties;

      public class Main {

      public static void main(String\[\] args) throws Exception {
      	// TODO Auto-generated method stub
      			  
      	    try {
      	      Class.forName("com.mysql.jdbc.Driver");
      	      Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/student?useSSL=true","root","success");  
      	      System.out.print("Database is connected !");
      		  con.close();				
      }
      	    catch(Exception e)
      	    {
      	    	System.out.println(e.getMessage());
      	    	throw e;
      	    }
      	    	
      	    }
      

      }

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      That message most likely means that JDBC cannot connect through port 3306, the mysql driver is not listening there, or some part of that path is not valid.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups