Hello,
I'm using Netbeans with JDK 7. I'm developing a swing desktop application with embedded derby database.
I'm using the following code.

Statement stmt;
        try {
            Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
            Connection conn =
                    DriverManager.getConnection("jdbc:derby://localhost:1527/HelloWorld", "userid", "password");
            stmt = conn.createStatement();
            String sql = "INSERT INTO TABLEEMP " +
                    "VALUES (" + Integer.parseInt(jTextField1.getText()) + ", '" + jTextField2.getText() + "')";
            stmt.executeUpdate(sql);
            JOptionPane.showMessageDialog(null, "Success");
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage());

When i'm running this piece of code in Netbeans it's working fine. But when I close NetBeans and doubly click on the JAR file, it's throwing the following error:
java.net.ConnectException : Error connectiong to server localhost on port 1527 with message Connection refused : Connect

So, how to connect derby DB for distributed jar ?
How can i overcome this. Please help...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.