0

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 Commented Sep 24, 2012 at 5:01

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

i always connect to the database in the server using sql plus , is there a different connector for sql plus , since the one i am using now is for mysql

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.