Results 1 to 10 of 10
  1. #1
    juamd is offline Member
    Join Date
    Apr 2010
    Posts
    25
    Rep Power
    0

    Default Problem with getConnection

    Hello.

    I have an application that connects to a database but it is very slow, I tried to use ODBC and mysql connector but it is still slow. Here is the code:

    Java Code:
    final String USUARIO = "usuario";
       final String CLAVE = "clave";
       final String BD = "basededatos";
       final String SERVIDOR = "jdbc:mysql://ip_del_servidor/"+BD; 
      
    public void conectar()
        {
            try{
                   Class.forName("com.mysql.jdbc.Driver");
                    this.conexion = DriverManager.getConnection(SERVIDOR,USUARIO,CLAVE);
                
                
            }
            catch(ClassNotFoundException e){
                e.printStackTrace();
            }
            catch(SQLException e){
                e.printStackTrace();
            }
        }
    
    if use ODBC :
    
     final String SERVIDOR = "ip_del_servidor"; 
    
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    
      this.conexion = DriverManager.getConnection("jdbc:odbc:"+BD);
    The problem is in the method "getConnection". I tried to disable the antivirus, window's firewall, but there is no change. Ping works.

    any suggestions ?

    Thanks.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Why you specify the drivers like this?

    Java Code:
    Class.forName("com.mysql.jdbc.Driver");

  3. #3
    juamd is offline Member
    Join Date
    Apr 2010
    Posts
    25
    Rep Power
    0

    Default

    Hi,

    That is the way I found in internet. How should I specify the driver ?

    the server is remote.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  5. #5
    juamd is offline Member
    Join Date
    Apr 2010
    Posts
    25
    Rep Power
    0

    Default

    Hi, thanks for answering.

    I used the way exposed in the mysql connector j tutorial, even so I used jdbc-odbc bridge to find if the problem was in the connector so I realized the problem was in the method getConnection. Doesn't matter the way I specify the connector I'm getting the same problem.

    Thanks.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Hope you've a clear idea about the connection bridge.

    Actually the connection not much to do with that. Only thing is it'll effect on with the table data, basically how you query data from the database?

    Normally long it'll take to open the connection?

  7. #7
    juamd is offline Member
    Join Date
    Apr 2010
    Posts
    25
    Rep Power
    0

    Default

    I installed mysql as local server then I tried to connect it and the connection was succesfull and fast, the problem is in the red.

    Thanks a lot.

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    May be the connections on your other PC is not well. Where your other PC is located, how long it'll take to reach through the IP?

  9. #9
    juamd is offline Member
    Join Date
    Apr 2010
    Posts
    25
    Rep Power
    0

    Default

    The problem was solved, the mysql server has a table named host which contains the pcs who have to connect it, I forgot to add the ip's pc to a that table.

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Replies: 0
    Last Post: 09-11-2009, 06:53 PM
  2. DriverManger.getConnection
    By mransome in forum Advanced Java
    Replies: 1
    Last Post: 08-13-2007, 03:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •