How to connect to a database using a distributed API?

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.

Upvotes: 0

Views: 252

Answers (1)

bzzzrd
bzzzrd

Reputation: 381

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

Upvotes: 1

Related Questions