0

I am creating a java console application that connects to a MySQL database. I have outlined below what I've done but the connection is not being established:

Things I have done:

1) I have added the mysql-connector-java-5.1.36.jar to my project bulid path.

2) I have written the code that tries to establish a connection

Can anyone suggest what I'm doing wrong?

The code is given below:

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

public class main {

  public static void main(String[] args) {

    try {

      Class.forName("com.mysql.jdbc.Driver");

      Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:1234/first","root","");
      System.out.println("Success fully Connected");

    } catch (Exception ex) {
        System.out.println(ex.getMessage());    
    }
  }
}
pelumi
  • 1,530
  • 12
  • 21
Hassan
  • 35
  • 9
  • If you dint change the default mysql configuration then the default port is 3306 – singhakash Sep 29 '15 at 09:59
  • i am using jre 8. i have change the port no.. – Hassan Sep 29 '15 at 10:00
  • it is giving error mysql-connector-java-5.1.36 has no source attach ?? what can I do next ? – Hassan Sep 29 '15 at 10:07
  • what IDE you are using and did you changed the mysql default port – singhakash Sep 29 '15 at 10:10
  • you need to connect to mysql not to phpmyadmin. – Oyeme Sep 29 '15 at 10:41
  • I am using eclipse mars. and I have change mysql port, it is now 1234, I am trying to connect to mysql but being unsuccessful all the time – Hassan Sep 29 '15 at 10:47
  • check http://stackoverflow.com/questions/12013685/source-not-found-the-jar-file-mysql-connector-java-5-1-20-bin-jar-has-no-source – singhakash Sep 29 '15 at 10:58
  • Thank you every one, my problem has been solved, the mistake I was doing was that, I have change my xampp port no, and I was putting this on connection url, i should have included sql port number. thank you every once again for replies, really appreciated your help. – Hassan Oct 09 '15 at 12:29

0 Answers0