Results 1 to 6 of 6
Like Tree3Likes
  • 1 Post By Tolls
  • 1 Post By Tolls
  • 1 Post By Tolls

Thread: error: org.apache.derby.client.am.DisconnectException: java.net.BindException

  1. #1
    superparca is offline Member
    Join Date
    Jan 2012
    Posts
    3
    Rep Power
    0

    Post error: org.apache.derby.client.am.DisconnectException: java.net.BindException

    Hello,
    I wrote a program and I use the database derby. When I run the program I have the following error:

    org.apache.derby.client.am.DisconnectException: java.net.BindException : Error opening socket to server localhost on port 1527 with message : Address already in use: connect


    The program connect and disconnect from the database a lot of time, and I think that it's the problem. Someone can help me?

    The code is the following:


    Java Code:
    try{Class.forName("org.apache.derby.jdbc.ClientDriver");          
               }catch(ClassNotFoundException e){
                System.out.println(e);
                System.out.println("errore di connessione al driver");}
           
            try{
                Connection con = DriverManager.getConnection("jdbc:derby:"
                        + "//localhost:1527/speranza","marco","marco");
                
                Statement addDB=null;
                addDB= con.createStatement();
                    
                ResultSet rs = addDB.executeQuery("SELECT UM, TIME, VALORE, "
                        + "CONTEGGIO, FIBRA FROM APP.TABELLA");
                    
                //conta_step mi permette di contare i vari step, e la confronto
                //con il tempo di attivazione delle UM
                int conta_step=0;
                
                //In x1 salvo il valore del tempo delle UM(in uno stesso istante
                //possono essere attive tutte le UM)
                //In x2 salvo il valore dei 17 punti della sinusoide della UM
                double []x1= new double[SistemaNervoso.UMattive+1];
                double []x2= new double[17];
                
                //int j1 č il contatore di x1, x1[j1];mi permette di confrontare
                //i vari tempi delle UM
                int j1=0;
                
                //flag4 mi permette di salvare i valori della sinusoide della UM
                //in modo tale che se ho un'altra UM attiva vado a sommare a questi
                //punti salvati i valori della nuova sinusoide
                int flag4=0;
                
                //inizio a leggere la prima riga
                rs.next();
                
                //inizio il ciclo do-while
                do{
                    //inizializzo ad ogni step di tempo j1 e flag4 a zero, in modo
                    //tale che ad ogni step riparto da zero
                    j1=0;
                    flag4=0;
                    //inizializzo x2[j] a zero
                    for(int j=0;j<17;j++)
                    {
                        x2[j]=0;
                    }
                    //incremento il conteggio degli step
                    conta_step=conta_step+1;
                    
                    //verifico se il tempo dell'UM č uguale a quello dello step
                    if(conta_step==rs.getInt(2))
                    {
                        System.out.println("+++++++++++++++++++++++++++++++++");
                        System.out.println("step="+conta_step);
                        //System.out.println("ok3");
                        //faccio il ciclo for per sommare le UM con lo stesso tempo
                        for(int i=0;i<SistemaNervoso.UMattive;i++)
                        {
                            System.out.println("i="+i);
                            //in un primo momento (flag4!=1) salvo il valore della
                            //sinusoide della prima UM,successivamente andrņ a
                            //vedere se questa UM ha lo stesso tempo di attivazione
                            //della/e successiva/e UM
                            if(flag4!=1)
                            {
                                //savlo in X1 il tempo dell'UM
                                x1[j1]=rs.getInt(2);
                                
                                //System.out.println("ok5");
                                //sommo tutte le fibre appartenenti alla stessa UM
                                for(int k=0;k<numberFiber;k++)
                                {
                                    //salvo con questo ciclo for tutti e i 17 punti 
                                    //della sinusoide
                                    for(int j=0;j<17;j++)
                                    {
                                        x2[j]=rs.getDouble(3)+x2[j];
                                        
                                        //System.out.println("x2["+j+"]="+x2[j]);
                                        //passo alla riga succesiva del database
                                        rs.next();
                                    }
                                    
                                }   
                                //pongo flag4=1 in modo tale da non rientra in 
                                //questo ciclo
                                flag4=1;    
                            }
                                    //prova da cancellare
                                    for(int j=0;j<17;j++)
                                    {
                                        
                                       System.out.println("x2["+j+"]="+x2[j]);
                                       
                                    }
                            
                            //System.out.println("ok10");
                            //incremento la variabile j1 di 1 in modo da salvarmi
                            //il nuovo valore del tempo della nuova UM in x1
                            //System.out.println("x1["+j1+"]="+x1[j1]);
                            j1=j1+1;
                            //System.out.println("j1="+j1);
                            x1[j1]=rs.getInt(2);
                         
                            //System.out.println("x1[j1+1]="+x1[j1]);
                            //confronto il tempo dell'UM con quella precedente
                            //se sono uguali sommo i singoli punti della sinusoide
                            //altrimenti esco dal ciclo for
                            if(x1[j1]==x1[j1-1])
                            {
                                //System.out.println("ok12");
                                for(int k=0;k<numberFiber;k++)
                                {
                                    for(int j=0;j<17;j++)
                                    {
                                        x2[j]=x2[j]+rs.getDouble(3);
                                        rs.next();
                                    }
                                }
                            }
                            else
                            {
                                //pongo i uguale al numro di UMattive in modo da 
                                //uscire dal ciclo for
                                i=SistemaNervoso.UMattive;
                                //System.out.println("ok11");
                            }            
                        
                        }
    
                        System.out.println("ok8-finito di sommare UM dello stesso "
                                + "tempo");
                        //salvo il valore di ogni punto della sinusoide nel
                        //database "graficoDB"
                        for(int i=0;i<17;i++)
                        {
    
                            try{Class.forName("org.apache.derby.jdbc.ClientDriver");           
                                }catch(ClassNotFoundException e){
                            System.out.println(e);
                            System.out.println("errore di connessione al driver");}
                            
                            try{
                                Connection con2 = DriverManager.getConnection(""
                                        + "jdbc:derby://localhost:1527/graficoDB",
                                        "marco","marco");
    
                                PreparedStatement addDB2 = null;
    
                                String addString2 = "INSERT INTO app.grafico (x,y)"
                                        + " VALUES (?,?)";
                                addDB2 = con2.prepareStatement(addString2);
                                
                                //sull'asse x metto ascissa che č il tempo
                                //sull'asse y il valore della sinusoide
                                double ascissa= x1[j1-1]+i*0.01;
                                addDB2.setDouble(1,ascissa);
                                addDB2.setDouble(2,x2[i]);
                                
                                addDB2.executeUpdate();
                                addDB2.close();
                                con2.close();
                               } catch (SQLException e) {
                                    e.printStackTrace();
                                    System.out.println("errore di connessione al "
                                            + "database"); }
    
                        }
                    }
                    
                    //se i tempi dell'UM e dello step sono diversi nel database
                    //"graficoDB" inserisco in x il valore dello step e in y zero
                    else
                    {
    
                        try{Class.forName("org.apache.derby.jdbc.ClientDriver");           
                        }catch(ClassNotFoundException e){
                        System.out.println(e);
                        System.out.println("errore di connessione al driver");}
    
                        try{
                            Connection con4 = DriverManager.getConnection(""
                                    + "jdbc:derby://localhost:1527/graficoDB",
                                    "marco","marco");
    
                            PreparedStatement addDB4 = null;
    
                            String addString4 = "INSERT INTO app.grafico (x,y)"
                                + " VALUES (?,?)";
                            addDB4 = con4.prepareStatement(addString4);
                            addDB4.setDouble(1,conta_step);
                            addDB4.setDouble(2,0 );
    
                            addDB4.executeUpdate();
                            addDB4.close();
                            con4.close();
                            
                           } catch (SQLException e) {
                           e.printStackTrace();
                           System.out.println("errore di connessione al database");}
                        
                    }
                    
                }while(conta_step<=(tempo2*1000));
            
                rs.close();
                addDB.close();
                con.close();
            } catch(Exception e){System.err.println(e);}

    Thank you
    Last edited by superparca; 01-27-2012 at 12:47 PM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default Re: error: org.apache.derby.client.am.DisconnectException: java.net.BindException

    Do you get any other exceptions prior to this, from your INSERT code for example?
    I'm asking because you do not close your connection in a finally block and so if you get an exception in the try block after opening a connection then that connection will not be closed off.

    Note, this may well not be your problem...
    superparca likes this.

  3. #3
    superparca is offline Member
    Join Date
    Jan 2012
    Posts
    3
    Rep Power
    0

    Default Re: error: org.apache.derby.client.am.DisconnectException: java.net.BindException

    Quote Originally Posted by Tolls View Post
    Do you get any other exceptions prior to this, from your INSERT code for example?
    I'm asking because you do not close your connection in a finally block and so if you get an exception in the try block after opening a connection then that connection will not be closed off.

    Note, this may well not be your problem...

    No, I don't have other error. I edit the code because I put the wrong one :( sorry. Now it's the correct one.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default Re: error: org.apache.derby.client.am.DisconnectException: java.net.BindException

    Have you traced which connection is causing the problem?
    Second, third, fourth...
    superparca likes this.

  5. #5
    superparca is offline Member
    Join Date
    Jan 2012
    Posts
    3
    Rep Power
    0

    Default Re: error: org.apache.derby.client.am.DisconnectException: java.net.BindException

    Quote Originally Posted by Tolls View Post
    Do you get any other exceptions prior to this, from your INSERT code for example?
    I'm asking because you do not close your connection in a finally block and so if you get an exception in the try block after opening a connection then that connection will not be closed off.

    Note, this may well not be your problem...
    Quote Originally Posted by Tolls View Post
    Have you traced which connection is causing the problem?
    Second, third, fourth...
    Thank you very much for this simple but great advice. The error is not in these databases but in the database of the first code that I have posted. I try to change the code to reduce the times of how often I connect to that database and now the code run correctly. I think that the problem is that I try to connect to many times to that database.
    I don't know how to say thank you, but you solve a big problem for my thesis!!
    thank you very much!!

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default Re: error: org.apache.derby.client.am.DisconnectException: java.net.BindException

    It's an odd error to get when the db runs out of connections, but good job on finding it.
    superparca likes this.

Similar Threads

  1. Replies: 5
    Last Post: 11-30-2011, 09:27 AM
  2. Replies: 4
    Last Post: 11-10-2011, 05:43 PM
  3. Replies: 1
    Last Post: 09-12-2011, 10:42 AM
  4. Replies: 2
    Last Post: 11-10-2009, 04:29 PM
  5. java.net.BindException
    By techbossmb in forum JDBC
    Replies: 0
    Last Post: 10-13-2009, 04:56 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
  •