0

I'm having trouble with my distributed application in java netbeans the program is running perfectly on the original machine where i created it. but when i build it and make a distribute folder and follow the instructions and try to run it, I got an error that localhost on port 1527 has been refused.

here is my code on my do connect function

public void DoConnect()
{
    String host = "jdbc:derby://localhost:1527/KempDB";
    String uName = "main";
    String uPass = "admin";
    try
    {
        con = DriverManager.getConnection(host, uName, uPass);
        stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);

        String sql = "select cv.checkvouchernumber, c.checknumber, paytoorder, bankcode, dateissued, amount from checkvoucher cv, checks c where cv.checkvouchernumber = c.checkvouchernumber and cv.checknumber = c.checknumber";
        rs = stmt.executeQuery(sql);.....
        ..........
    }
    catch(SQLException err){
        .......
    }

so this is the code I used to connect with the database server, the database server I used is built-in with java. Its a apache derby...

like I said in the original machine where I created the program runs ok without errors but when I distribute the program to another machine there's an error refusing the connection. How can I connect to the local machine where my database is? maybe you can help me on this.

7
  • Are you able to connect via a database management tool like Heidi SQL? Commented Jun 25, 2013 at 9:12
  • 2
    Replace localhost with ip address of machine on which your database is present.Let me know if it's working. Commented Jun 25, 2013 at 9:18
  • @Templar no sir I don't use Heidi SQL. Commented Jun 26, 2013 at 4:57
  • @R.S :I will try to use IP sir I will let you know immediately. Commented Jun 26, 2013 at 4:58
  • @R.S Hi sir, I have tried changing the localhost to the machines IP where the database is; and I encounter an error "DERBY SQL error:SQLCODE:-1, SQLSTATE:08004, SQLERRMC: Database connection refused". I hope you can help me with this Commented Jun 26, 2013 at 5:07

1 Answer 1

1

Are the database Servers running on these machines? Are u starting the database server programmatically?

If you try to connect a database Server with:

jdbc:derby://localhost:1527/KempDB

This Server needs to be up and running.

For your case you should use an embedded Database. For the case your Database is already an embedded Database, then you can try using this URL:

jdbc:derby:KempDB

instead of:

jdbc:derby://localhost:1527/KempDB

Hav a look on this one

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

2 Comments

only one machine runs the database server and I started that server sir., mr. R.S. answered my question, when I distribute my program to a client machine I should change the localhost to an IP of the server that runs the database server.,
how ever your suggestion is great if the application I'm working is a standalone application, which is not what I am doing now. anyways thanks for the suggestion sir I will consider it for my standalone application.

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.