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)

j.w.r
  • 4,136
  • 2
  • 27
  • 29
abhinav
  • 57
  • 1
  • 8
  • You might want to have read of this [question](http://stackoverflow.com/questions/2983248/com-mysql-jdbc-exceptions-jdbc4-communicationsexception-communications-link-fai) – MadProgrammer Sep 24 '12 at 05:01

1 Answers1

2

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

Hernan Velasquez
  • 2,770
  • 14
  • 21
  • 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 – abhinav Sep 24 '12 at 05:23