简体   繁体   中英

Distribution of java project containing javadb made in Netbeans

I've just completed my java application & am now trying to distribute it. The build works fine, but when tried on another PC I receive the error:

java.sql.SQLNonTransientConnectionException: java.net.ConnectException : Error connecting to server localhost on port 1,527 with message Connection refused: connect.

The code being run is

         try
    {
    Connection conn = null;
    conn = DriverManager.getConnection ("jdbc:derby://localhost:1527/db01", "Administrator", "admin"); //run procedure getConnection to connect to the database - see below
    PreparedStatement st =conn.prepareStatement("Select * from TB01");
    ResultSet rs = st.executeQuery();
   jTable1.setModel(DbUtils.resultSetToTableModel(rs));
    conn.close();
    }
    catch(Exception ex)
    {
    JOptionPane.showMessageDialog(null, ex.toString());
    }

I'm assuming that I'm missing something for setting parameters for when the code is run outside of IDE. Could anyone please explain to me what else I have to include?

TB01 is just a table containing some sample data, that I am trying to display on the gui. It works perfectly from within IDE

It does not work on my pc once I have closed IDE. Do you have to include some code to start the server?

Thanks in advance

You should probably use JavaDB in an embedded mode. Then you don't need to start the server and no network traffic is needed. I think it's called "Java DB (Embedded)" in Netbeans.

Here is an old howto: https://blogs.oracle.com/geertjan/entry/embedded_database_for_netbeans_platform

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM