0
votes

I am new to Java, and I need your help please.
I have a sql database in the server and always use sql plus to log into the database when in the cmd of the server. On the client PC when I tried to develop a configuration string, I am using mysql connector, will it work? Is it possible to use mysql connector for establishing connection with sql?

This is my code:

            public class Connection_String {

      static public final String driver = "com.mysql.jdbc.Driver";
      static public final String    connection= "jdbc:mysql://192.168.2.22:1521/nameofdatabase ";
      static public final String user = "user" ; 
      static public final String password = "password"; //connection password 



      public static void main(String[] args) throws ClassNotFoundException, SQLException 
      {
        try 
        {
            Class.forName(driver);
            Connection con = DriverManager.getConnection(connection,user,password);
            System.out.println(" Connection string : ");
            System.out.println(connection);
            System.out.println("User Name " + user );
            System.out.println("password" + password);

            if (!con.isClosed())
            { 
                con.close();
            }

These are the errors :

Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source)

1
You might want to have read of this question - MadProgrammer

1 Answers

2
votes

Are you sure that your mysql is listening sockets at port 1521? By default, mysql is configured to use the port 3306.