You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by steve lescure <st...@yahoo.com> on 2011/04/19 21:45:54 UTC

problem with embedded driver

I create a java desktop application using Netbeans that uses the embedded derby driver.  it works fine as long as i connect to the database manually within Netbeans.  If I don't, i get a return code of 8000/4001 connection refused.

I created a project in Netbeans using the derby demo application too, so i could see if the problem was my code or something else.  I have the same problem.  it only works if i right click on the database in Netbeans and 
choose "connect".   

i seem to be missing something fundamental here.  

can anybody help?

package ondemand;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Properties;

public class DemandDatabase {

    private String framework = "embedded";
    private String driver = "org.apache.derby.jdbc.EmbeddedDriver";
    private String protocol = "jdbc:derby:";

    public DemandDatabase() {
        System.out.println("in constructor ");
    }

    public ArrayList go() 
    {
        System.out.println("about to load the driver in " + framework + " mode");
        loadDriver();
        Connection conn = null;

        ArrayList statements = new ArrayList();
        ArrayList jobnames = new ArrayList();

        Statement s = null;
        ResultSet rs = null;

        try {
            Properties props = new Properties(); // connection properties
            props.put("user", "nbuser");
            props.put("password", "nbuser");
            String dbName = "//localhost:1527/users"; // the name of the database
            conn = DriverManager.getConnection(protocol + dbName
                    + ";create=false", props);
            System.out.println("Connected to database " + dbName);

            conn.setAutoCommit(true);
            s = conn.createStatement();
            statements.add(s);
            rs = s.executeQuery(
                    "SELECT JOBNAME, USERID FROM APP.JOBS");
            String txtJobname;
            String txtUserID;

            while (rs.next()) {
                txtJobname = rs.getString("JOBNAME");
                System.out.println("value of jobname is " + txtJobname);
                txtUserID = rs.getString("USERID");
                System.out.println("value of User ID is " + txtUserID);
                jobnames.add(txtJobname);
            }

            try {
                // the shutdown=true attribute shuts down Derby
                DriverManager.getConnection("jdbc:derby:;shutdown=true");
            } catch (SQLException se) {
                if (((se.getErrorCode() == 50000)
                        && ("XJ015".equals(se.getSQLState())))) {
                    // we got the expected exception
                    System.out.println("Derby shut down normally");
                    // Note that for single database shutdown, the expected
                    // SQL state is "08006", and the error code is 45000.
                } else {
                    // if the error code or SQLState is different, we have
                    // an unexpected exception (shutdown failed)
                    System.out.println("Derby did not shut down normally");
                    printSQLException(se);
                }
            }
        } catch (SQLException sqle) {
            printSQLException(sqle);
        } finally {
            // release all open resources to avoid unnecessary memory usage
            try {
                if (rs != null) {
                    rs.close();
                    rs = null;
                }
            } catch (SQLException sqle) {
                printSQLException(sqle);
            }

            // Statements and PreparedStatements
            int i = 0;
            while (!statements.isEmpty()) {
                // PreparedStatement extend Statement
                Statement st = (Statement) statements.remove(i);
                try {
                    if (st != null) {
                        st.close();
                        st = null;
                    }
                } catch (SQLException sqle) {
                    printSQLException(sqle);
                }
            }
            //Connection
            try {
                if (conn != null) {
                    conn.close();
                    conn = null;
                }
            } catch (SQLException sqle) {
                printSQLException(sqle);
            }
        }
        return jobnames;
    }

    private void loadDriver() {
        try {
            Class.forName(driver).newInstance();
            System.out.println("Loaded the appropriate driver");
        } catch (ClassNotFoundException cnfe) {
            System.err.println("\nUnable to load the JDBC driver " + driver);
            System.err.println("Please check your CLASSPATH.");
            cnfe.printStackTrace(System.err);
        } catch (InstantiationException ie) {
            System.err.println(
                    "\nUnable to instantiate the JDBC driver " + driver);
            ie.printStackTrace(System.err);
        } catch (IllegalAccessException iae) {
            System.err.println(
                    "\nNot allowed to access the JDBC driver " + driver);
            iae.printStackTrace(System.err);
        }
    }

    private void reportFailure(String message) {
        System.err.println("\nData verification failed:");
        System.err.println('\t' + message);
    }

    public static void printSQLException(SQLException e) {
        // Unwraps the entire exception chain to unveil the real cause of the
        // Exception.
        while (e != null) {
            System.err.println("\n----- SQLException -----");
            System.err.println("  SQL State:  " + e.getSQLState());
            System.err.println("  Error Code: " + e.getErrorCode());
            System.err.println("  Message:    " + e.getMessage());
            // for stack traces, refer to derby.log or uncomment this:
            //e.printStackTrace(System.err);
            e = e.getNextException();
        }
    }
}

RE: problem with embedded driver

Posted by Daniel A Keefe <da...@convergys.com>.
no.  ij is strictly a manual tool.

dk

________________________________________
From: steve lescure [stevelescure@yahoo.com]
Sent: Tuesday, April 19, 2011 4:36 PM
To: Derby Discussion
Subject: RE: problem with embedded driver

ok - i see some examples of using "ij" to manually create the connection, that makes sense.


i thought if i were using the embedded driver it would automatically start derby.....

would i need to somehow call "ij" in my java code?

package ondemand;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Properties;

public class DemandDatabase {

    private String framework = "embedded";
    private String driver = "org.apache.derby.jdbc.EmbeddedDriver";
    private String protocol = "jdbc:derby:";

    public DemandDatabase() {
        System.out.println("in constructor ");
    }

    public ArrayList go() // void go(String[] args)
    {
        System.out.println("about to load the driver in " + framework + " mode");
        loadDriver();
        Connection conn = null;

        ArrayList statements = new ArrayList();
        ArrayList jobnames = new ArrayList();

        Statement s = null;
        ResultSet rs = null;

        try {
            Properties props = new Properties(); // connection properties
            props.put("user", "nbuser");
            props.put("password", "nbuser");
            String dbName = "//localhost:1527/users"; // the name of the database
            conn = DriverManager.getConnection(protocol + dbName
                    + ";create=true", props);
            System.out.println("Connected to database " + dbName);

            conn.setAutoCommit(true);
            s = conn.createStatement();
            statements.add(s);
            rs = s.executeQuery(
                    "SELECT JOBNAME, USERID FROM APP.JOBS");
            String txtJobname;
            String txtUserID;

            while (rs.next()) {
                txtJobname = rs.getString("JOBNAME");
                System.out.println("value of jobname is " + txtJobname);
                txtUserID = rs.getString("USERID");
                System.out.println("value of User ID is " + txtUserID);
                jobnames.add(txtJobname);
            }

            try {
                // the shutdown=true attribute shuts down Derby
                DriverManager.getConnection("jdbc:derby:;shutdown=true");
            } catch (SQLException se) {
                if (((se.getErrorCode() == 50000)
                        && ("XJ015".equals(se.getSQLState())))) {
                    // we got the expected exception
                    System.out.println("Derby shut down normally");
                    // Note that for single database shutdown, the expected
                    // SQL state is "08006", and the error code is 45000.
                } else {
                    // if the error code or SQLState is different, we have
                    // an unexpected exception (shutdown failed)
                    System.out.println("Derby did not shut down normally");
                    printSQLException(se);
                }
            }
        } catch (SQLException sqle) {
            printSQLException(sqle);
        } finally {
            // release all open resources to avoid unnecessary memory usage
            try {
                if (rs != null) {
                    rs.close();
                    rs = null;
                }
            } catch (SQLException sqle) {
                printSQLException(sqle);
            }

            // Statements and PreparedStatements
            int i = 0;
            while (!statements.isEmpty()) {
                // PreparedStatement extend Statement
                Statement st = (Statement) statements.remove(i);
                try {
                    if (st != null) {
                        st.close();
                        st = null;
                    }
                } catch (SQLException sqle) {
                    printSQLException(sqle);
                }
            }
            //Connection
            try {
                if (conn != null) {
                    conn.close();
                    conn = null;
                }
            } catch (SQLException sqle) {
                printSQLException(sqle);
            }
        }
        return jobnames;
    }

    private void loadDriver() {
        try {
            Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
            System.out.println("Loaded the appropriate driver");
        } catch (ClassNotFoundException cnfe) {
            System.err.println("\nUnable to load the JDBC driver " + driver);
            System.err.println("Please check your CLASSPATH.");
            cnfe.printStackTrace(System.err);
        } catch (InstantiationException ie) {
            System.err.println(
                    "\nUnable to instantiate the JDBC driver " + driver);
            ie.printStackTrace(System.err);
        } catch (IllegalAccessException iae) {
            System.err.println(
                    "\nNot allowed to access the JDBC driver " + driver);
            iae.printStackTrace(System.err);
        }
    }

    private void reportFailure(String message) {
        System.err.println("\nData verification failed:");
        System.err.println('\t' + message);
    }

    public static void printSQLException(SQLException e) {
        // Unwraps the entire exception chain to unveil the real cause of the
        // Exception.
        while (e != null) {
            System.err.println("\n----- SQLException -----");
            System.err.println("  SQL State:  " + e.getSQLState());
            System.err.println("  Error Code: " + e.getErrorCode());
            System.err.println("  Message:    " + e.getMessage());
            // for stack traces, refer to derby.log or uncomment this:
            //e.printStackTrace(System.err);
            e = e.getNextException();
        }
    }
}

NOTICE:  The information contained in this electronic mail transmission is intended by Convergys Corporation for the use of the named individual or entity to which it is directed and may contain information that is privileged or otherwise confidential.  If you have received this electronic mail transmission in error, please delete it from your system without copying or forwarding it, and notify the sender of the error by reply email or by telephone (collect), so that the sender's address records can be corrected.

RE: problem with embedded driver

Posted by steve lescure <st...@yahoo.com>.
ok - i see some examples of using "ij" to manually create the connection, that makes sense. 


i thought if i were using the embedded driver it would automatically start derby.....

would i need to somehow call "ij" in my java code?

package ondemand;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Properties;

public class DemandDatabase {

    private String framework = "embedded";
    private String driver = "org.apache.derby.jdbc.EmbeddedDriver";
    private String protocol = "jdbc:derby:";

    public DemandDatabase() {
        System.out.println("in constructor ");
    }

    public ArrayList go() // void go(String[] args)
    {
        System.out.println("about to load the driver in " + framework + " mode");
        loadDriver();
        Connection conn = null;

        ArrayList statements = new ArrayList();
        ArrayList jobnames = new ArrayList();

        Statement s = null;
        ResultSet rs = null;

        try {
            Properties props = new Properties(); // connection properties
            props.put("user", "nbuser");
            props.put("password", "nbuser");
            String dbName = "//localhost:1527/users"; // the name of the database
            conn = DriverManager.getConnection(protocol + dbName
                    + ";create=true", props);
            System.out.println("Connected to database " + dbName);

            conn.setAutoCommit(true);
            s = conn.createStatement();
            statements.add(s);
            rs = s.executeQuery(
                    "SELECT JOBNAME, USERID FROM APP.JOBS");
            String txtJobname;
            String txtUserID;

            while (rs.next()) {
                txtJobname = rs.getString("JOBNAME");
                System.out.println("value of jobname is " + txtJobname);
                txtUserID = rs.getString("USERID");
                System.out.println("value of User ID is " + txtUserID);
                jobnames.add(txtJobname);
            }

            try {
                // the shutdown=true attribute shuts down Derby
                DriverManager.getConnection("jdbc:derby:;shutdown=true");
            } catch (SQLException se) {
                if (((se.getErrorCode() == 50000)
                        && ("XJ015".equals(se.getSQLState())))) {
                    // we got the expected exception
                    System.out.println("Derby shut down normally");
                    // Note that for single database shutdown, the expected
                    // SQL state is "08006", and the error code is 45000.
                } else {
                    // if the error code or SQLState is different, we have
                    // an unexpected exception (shutdown failed)
                    System.out.println("Derby did not shut down normally");
                    printSQLException(se);
                }
            }
        } catch (SQLException sqle) {
            printSQLException(sqle);
        } finally {
            // release all open resources to avoid unnecessary memory usage
            try {
                if (rs != null) {
                    rs.close();
                    rs = null;
                }
            } catch (SQLException sqle) {
                printSQLException(sqle);
            }

            // Statements and PreparedStatements
            int i = 0;
            while (!statements.isEmpty()) {
                // PreparedStatement extend Statement
                Statement st = (Statement) statements.remove(i);
                try {
                    if (st != null) {
                        st.close();
                        st = null;
                    }
                } catch (SQLException sqle) {
                    printSQLException(sqle);
                }
            }
            //Connection
            try {
                if (conn != null) {
                    conn.close();
                    conn = null;
                }
            } catch (SQLException sqle) {
                printSQLException(sqle);
            }
        }
        return jobnames;
    }

    private void loadDriver() {
        try {
            Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
            System.out.println("Loaded the appropriate driver");
        } catch (ClassNotFoundException cnfe) {
            System.err.println("\nUnable to load the JDBC driver " + driver);
            System.err.println("Please check your CLASSPATH.");
            cnfe.printStackTrace(System.err);
        } catch (InstantiationException ie) {
            System.err.println(
                    "\nUnable to instantiate the JDBC driver " + driver);
            ie.printStackTrace(System.err);
        } catch (IllegalAccessException iae) {
            System.err.println(
                    "\nNot allowed to access the JDBC driver " + driver);
            iae.printStackTrace(System.err);
        }
    }

    private void reportFailure(String message) {
        System.err.println("\nData verification failed:");
        System.err.println('\t' + message);
    }

    public static void printSQLException(SQLException e) {
        // Unwraps the entire exception chain to unveil the real cause of the
        // Exception.
        while (e != null) {
            System.err.println("\n----- SQLException -----");
            System.err.println("  SQL State:  " + e.getSQLState());
            System.err.println("  Error Code: " + e.getErrorCode());
            System.err.println("  Message:    " + e.getMessage());
            // for stack traces, refer to derby.log or uncomment this:
            //e.printStackTrace(System.err);
            e = e.getNextException();
        }
    }
}

RE: problem with embedded driver

Posted by Daniel A Keefe <da...@convergys.com>.
ij is the tool used to create a manual connection to the derby db


________________________________________
From: steve lescure [stevelescure@yahoo.com]
Sent: Tuesday, April 19, 2011 4:03 PM
To: Derby Discussion
Subject: RE: problem with embedded driver

thanks - i'm not following (very new to this).  "via ij"?

steve




--- On Tue, 4/19/11, Daniel A Keefe <da...@convergys.com> wrote:

> From: Daniel A Keefe <da...@convergys.com>
> Subject: RE: problem with embedded driver
> To: "Derby Discussion" <de...@db.apache.org>
> Date: Tuesday, April 19, 2011, 3:49 PM
> Steve;
>
> When you connect to the derby db via ij, the available db
> connections is NULL.
>
> dk
>
> ________________________________________
> From: steve lescure [stevelescure@yahoo.com]
> Sent: Tuesday, April 19, 2011 3:45 PM
> To: derby-user@db.apache.org
> Subject: problem with embedded driver
>
> I create a java desktop application using Netbeans that
> uses the embedded derby driver.  it works fine as long
> as i connect to the database manually within Netbeans.
> If I don't, i get a return code of 8000/4001 connection
> refused.
>
> I created a project in Netbeans using the derby demo
> application too, so i could see if the problem was my code
> or something else.  I have the same problem.  it
> only works if i right click on the database in Netbeans and
> choose "connect".
>
> i seem to be missing something fundamental here.
>
> can anybody help?
>
> package ondemand;
> import java.sql.Connection;
> import java.sql.DriverManager;
> import java.sql.PreparedStatement;
> import java.sql.ResultSet;
> import java.sql.SQLException;
> import java.sql.Statement;
> import java.util.ArrayList;
> import java.util.Properties;
>
> public class DemandDatabase {
>
>     private String framework = "embedded";
>     private String driver =
> "org.apache.derby.jdbc.EmbeddedDriver";
>     private String protocol = "jdbc:derby:";
>
>     public DemandDatabase() {
>         System.out.println("in
> constructor ");
>     }
>
>     public ArrayList go()
>     {
>         System.out.println("about to
> load the driver in " + framework + " mode");
>         loadDriver();
>         Connection conn = null;
>
>         ArrayList statements = new
> ArrayList();
>         ArrayList jobnames = new
> ArrayList();
>
>         Statement s = null;
>         ResultSet rs = null;
>
>         try {
>             Properties props
> = new Properties(); // connection properties
>             props.put("user",
> "nbuser");
>
> props.put("password", "nbuser");
>             String dbName =
> "//localhost:1527/users"; // the name of the database
>             conn =
> DriverManager.getConnection(protocol + dbName
>
>     + ";create=false", props);
>
> System.out.println("Connected to database " + dbName);
>
>
> conn.setAutoCommit(true);
>             s =
> conn.createStatement();
>
> statements.add(s);
>             rs =
> s.executeQuery(
>
>     "SELECT JOBNAME, USERID FROM APP.JOBS");
>             String
> txtJobname;
>             String
> txtUserID;
>
>             while (rs.next())
> {
>
> txtJobname = rs.getString("JOBNAME");
>
> System.out.println("value of jobname is " + txtJobname);
>
> txtUserID = rs.getString("USERID");
>
> System.out.println("value of User ID is " + txtUserID);
>
> jobnames.add(txtJobname);
>             }
>
>             try {
>                 //
> the shutdown=true attribute shuts down Derby
>
> DriverManager.getConnection("jdbc:derby:;shutdown=true");
>             } catch
> (SQLException se) {
>                 if
> (((se.getErrorCode() == 50000)
>
>         &&
> ("XJ015".equals(se.getSQLState())))) {
>
>     // we got the expected exception
>
>     System.out.println("Derby shut down
> normally");
>
>     // Note that for single database shutdown, the
> expected
>
>     // SQL state is "08006", and the error code is
> 45000.
>                 }
> else {
>
>     // if the error code or SQLState is different,
> we have
>
>     // an unexpected exception (shutdown failed)
>
>     System.out.println("Derby did not shut down
> normally");
>
>     printSQLException(se);
>                 }
>             }
>         } catch (SQLException sqle) {
>
> printSQLException(sqle);
>         } finally {
>             // release all
> open resources to avoid unnecessary memory usage
>             try {
>                 if
> (rs != null) {
>
>     rs.close();
>
>     rs = null;
>                 }
>             } catch
> (SQLException sqle) {
>
> printSQLException(sqle);
>             }
>
>             // Statements and
> PreparedStatements
>             int i = 0;
>             while
> (!statements.isEmpty()) {
>                 //
> PreparedStatement extend Statement
>
> Statement st = (Statement) statements.remove(i);
>                 try
> {
>
>     if (st != null) {
>
>         st.close();
>
>         st = null;
>
>     }
>                 }
> catch (SQLException sqle) {
>
>     printSQLException(sqle);
>                 }
>             }
>             //Connection
>             try {
>                 if
> (conn != null) {
>
>     conn.close();
>
>     conn = null;
>                 }
>             } catch
> (SQLException sqle) {
>
> printSQLException(sqle);
>             }
>         }
>         return jobnames;
>     }
>
>     private void loadDriver() {
>         try {
>
> Class.forName(driver).newInstance();
>
> System.out.println("Loaded the appropriate driver");
>         } catch (ClassNotFoundException
> cnfe) {
>
> System.err.println("\nUnable to load the JDBC driver " +
> driver);
>
> System.err.println("Please check your CLASSPATH.");
>
> cnfe.printStackTrace(System.err);
>         } catch (InstantiationException
> ie) {
>
> System.err.println(
>
>     "\nUnable to instantiate the JDBC driver " +
> driver);
>
> ie.printStackTrace(System.err);
>         } catch (IllegalAccessException
> iae) {
>
> System.err.println(
>
>     "\nNot allowed to access the JDBC driver " +
> driver);
>
> iae.printStackTrace(System.err);
>         }
>     }
>
>     private void reportFailure(String message) {
>         System.err.println("\nData
> verification failed:");
>         System.err.println('\t' +
> message);
>     }
>
>     public static void
> printSQLException(SQLException e) {
>         // Unwraps the entire exception
> chain to unveil the real cause of the
>         // Exception.
>         while (e != null) {
>
> System.err.println("\n----- SQLException -----");
>
> System.err.println("  SQL State:  " +
> e.getSQLState());
>
> System.err.println("  Error Code: " +
> e.getErrorCode());
>
> System.err.println("  Message:    " +
> e.getMessage());
>             // for stack
> traces, refer to derby.log or uncomment this:
>
> //e.printStackTrace(System.err);
>             e =
> e.getNextException();
>         }
>     }
> }
>
> NOTICE:  The information contained in this electronic
> mail transmission is intended by Convergys Corporation for
> the use of the named individual or entity to which it is
> directed and may contain information that is privileged or
> otherwise confidential.  If you have received this
> electronic mail transmission in error, please delete it from
> your system without copying or forwarding it, and notify the
> sender of the error by reply email or by telephone
> (collect), so that the sender's address records can be
> corrected.
>

NOTICE:  The information contained in this electronic mail transmission is intended by Convergys Corporation for the use of the named individual or entity to which it is directed and may contain information that is privileged or otherwise confidential.  If you have received this electronic mail transmission in error, please delete it from your system without copying or forwarding it, and notify the sender of the error by reply email or by telephone (collect), so that the sender's address records can be corrected.

RE: problem with embedded driver

Posted by steve lescure <st...@yahoo.com>.
thanks - i'm not following (very new to this).  "via ij"?

steve




--- On Tue, 4/19/11, Daniel A Keefe <da...@convergys.com> wrote:

> From: Daniel A Keefe <da...@convergys.com>
> Subject: RE: problem with embedded driver
> To: "Derby Discussion" <de...@db.apache.org>
> Date: Tuesday, April 19, 2011, 3:49 PM
> Steve;
> 
> When you connect to the derby db via ij, the available db
> connections is NULL.
> 
> dk
> 
> ________________________________________
> From: steve lescure [stevelescure@yahoo.com]
> Sent: Tuesday, April 19, 2011 3:45 PM
> To: derby-user@db.apache.org
> Subject: problem with embedded driver
> 
> I create a java desktop application using Netbeans that
> uses the embedded derby driver.  it works fine as long
> as i connect to the database manually within Netbeans. 
> If I don't, i get a return code of 8000/4001 connection
> refused.
> 
> I created a project in Netbeans using the derby demo
> application too, so i could see if the problem was my code
> or something else.  I have the same problem.  it
> only works if i right click on the database in Netbeans and
> choose "connect".
> 
> i seem to be missing something fundamental here.
> 
> can anybody help?
> 
> package ondemand;
> import java.sql.Connection;
> import java.sql.DriverManager;
> import java.sql.PreparedStatement;
> import java.sql.ResultSet;
> import java.sql.SQLException;
> import java.sql.Statement;
> import java.util.ArrayList;
> import java.util.Properties;
> 
> public class DemandDatabase {
> 
>     private String framework = "embedded";
>     private String driver =
> "org.apache.derby.jdbc.EmbeddedDriver";
>     private String protocol = "jdbc:derby:";
> 
>     public DemandDatabase() {
>         System.out.println("in
> constructor ");
>     }
> 
>     public ArrayList go()
>     {
>         System.out.println("about to
> load the driver in " + framework + " mode");
>         loadDriver();
>         Connection conn = null;
> 
>         ArrayList statements = new
> ArrayList();
>         ArrayList jobnames = new
> ArrayList();
> 
>         Statement s = null;
>         ResultSet rs = null;
> 
>         try {
>             Properties props
> = new Properties(); // connection properties
>             props.put("user",
> "nbuser");
>            
> props.put("password", "nbuser");
>             String dbName =
> "//localhost:1527/users"; // the name of the database
>             conn =
> DriverManager.getConnection(protocol + dbName
>                
>     + ";create=false", props);
>            
> System.out.println("Connected to database " + dbName);
> 
>            
> conn.setAutoCommit(true);
>             s =
> conn.createStatement();
>            
> statements.add(s);
>             rs =
> s.executeQuery(
>                
>     "SELECT JOBNAME, USERID FROM APP.JOBS");
>             String
> txtJobname;
>             String
> txtUserID;
> 
>             while (rs.next())
> {
>                
> txtJobname = rs.getString("JOBNAME");
>                
> System.out.println("value of jobname is " + txtJobname);
>                
> txtUserID = rs.getString("USERID");
>                
> System.out.println("value of User ID is " + txtUserID);
>                
> jobnames.add(txtJobname);
>             }
> 
>             try {
>                 //
> the shutdown=true attribute shuts down Derby
>                
> DriverManager.getConnection("jdbc:derby:;shutdown=true");
>             } catch
> (SQLException se) {
>                 if
> (((se.getErrorCode() == 50000)
>                
>         &&
> ("XJ015".equals(se.getSQLState())))) {
>                
>     // we got the expected exception
>                
>     System.out.println("Derby shut down
> normally");
>                
>     // Note that for single database shutdown, the
> expected
>                
>     // SQL state is "08006", and the error code is
> 45000.
>                 }
> else {
>                
>     // if the error code or SQLState is different,
> we have
>                
>     // an unexpected exception (shutdown failed)
>                
>     System.out.println("Derby did not shut down
> normally");
>                
>     printSQLException(se);
>                 }
>             }
>         } catch (SQLException sqle) {
>            
> printSQLException(sqle);
>         } finally {
>             // release all
> open resources to avoid unnecessary memory usage
>             try {
>                 if
> (rs != null) {
>                
>     rs.close();
>                
>     rs = null;
>                 }
>             } catch
> (SQLException sqle) {
>                
> printSQLException(sqle);
>             }
> 
>             // Statements and
> PreparedStatements
>             int i = 0;
>             while
> (!statements.isEmpty()) {
>                 //
> PreparedStatement extend Statement
>                
> Statement st = (Statement) statements.remove(i);
>                 try
> {
>                
>     if (st != null) {
>                
>         st.close();
>                
>         st = null;
>                
>     }
>                 }
> catch (SQLException sqle) {
>                
>     printSQLException(sqle);
>                 }
>             }
>             //Connection
>             try {
>                 if
> (conn != null) {
>                
>     conn.close();
>                
>     conn = null;
>                 }
>             } catch
> (SQLException sqle) {
>                
> printSQLException(sqle);
>             }
>         }
>         return jobnames;
>     }
> 
>     private void loadDriver() {
>         try {
>            
> Class.forName(driver).newInstance();
>            
> System.out.println("Loaded the appropriate driver");
>         } catch (ClassNotFoundException
> cnfe) {
>            
> System.err.println("\nUnable to load the JDBC driver " +
> driver);
>            
> System.err.println("Please check your CLASSPATH.");
>            
> cnfe.printStackTrace(System.err);
>         } catch (InstantiationException
> ie) {
>            
> System.err.println(
>                
>     "\nUnable to instantiate the JDBC driver " +
> driver);
>            
> ie.printStackTrace(System.err);
>         } catch (IllegalAccessException
> iae) {
>            
> System.err.println(
>                
>     "\nNot allowed to access the JDBC driver " +
> driver);
>            
> iae.printStackTrace(System.err);
>         }
>     }
> 
>     private void reportFailure(String message) {
>         System.err.println("\nData
> verification failed:");
>         System.err.println('\t' +
> message);
>     }
> 
>     public static void
> printSQLException(SQLException e) {
>         // Unwraps the entire exception
> chain to unveil the real cause of the
>         // Exception.
>         while (e != null) {
>            
> System.err.println("\n----- SQLException -----");
>            
> System.err.println("  SQL State:  " +
> e.getSQLState());
>            
> System.err.println("  Error Code: " +
> e.getErrorCode());
>            
> System.err.println("  Message:    " +
> e.getMessage());
>             // for stack
> traces, refer to derby.log or uncomment this:
>            
> //e.printStackTrace(System.err);
>             e =
> e.getNextException();
>         }
>     }
> }
> 
> NOTICE:  The information contained in this electronic
> mail transmission is intended by Convergys Corporation for
> the use of the named individual or entity to which it is
> directed and may contain information that is privileged or
> otherwise confidential.  If you have received this
> electronic mail transmission in error, please delete it from
> your system without copying or forwarding it, and notify the
> sender of the error by reply email or by telephone
> (collect), so that the sender's address records can be
> corrected.
> 

RE: problem with embedded driver

Posted by Daniel A Keefe <da...@convergys.com>.
Steve;

When you connect to the derby db via ij, the available db connections is NULL.

dk

________________________________________
From: steve lescure [stevelescure@yahoo.com]
Sent: Tuesday, April 19, 2011 3:45 PM
To: derby-user@db.apache.org
Subject: problem with embedded driver

I create a java desktop application using Netbeans that uses the embedded derby driver.  it works fine as long as i connect to the database manually within Netbeans.  If I don't, i get a return code of 8000/4001 connection refused.

I created a project in Netbeans using the derby demo application too, so i could see if the problem was my code or something else.  I have the same problem.  it only works if i right click on the database in Netbeans and
choose "connect".

i seem to be missing something fundamental here.

can anybody help?

package ondemand;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Properties;

public class DemandDatabase {

    private String framework = "embedded";
    private String driver = "org.apache.derby.jdbc.EmbeddedDriver";
    private String protocol = "jdbc:derby:";

    public DemandDatabase() {
        System.out.println("in constructor ");
    }

    public ArrayList go()
    {
        System.out.println("about to load the driver in " + framework + " mode");
        loadDriver();
        Connection conn = null;

        ArrayList statements = new ArrayList();
        ArrayList jobnames = new ArrayList();

        Statement s = null;
        ResultSet rs = null;

        try {
            Properties props = new Properties(); // connection properties
            props.put("user", "nbuser");
            props.put("password", "nbuser");
            String dbName = "//localhost:1527/users"; // the name of the database
            conn = DriverManager.getConnection(protocol + dbName
                    + ";create=false", props);
            System.out.println("Connected to database " + dbName);

            conn.setAutoCommit(true);
            s = conn.createStatement();
            statements.add(s);
            rs = s.executeQuery(
                    "SELECT JOBNAME, USERID FROM APP.JOBS");
            String txtJobname;
            String txtUserID;

            while (rs.next()) {
                txtJobname = rs.getString("JOBNAME");
                System.out.println("value of jobname is " + txtJobname);
                txtUserID = rs.getString("USERID");
                System.out.println("value of User ID is " + txtUserID);
                jobnames.add(txtJobname);
            }

            try {
                // the shutdown=true attribute shuts down Derby
                DriverManager.getConnection("jdbc:derby:;shutdown=true");
            } catch (SQLException se) {
                if (((se.getErrorCode() == 50000)
                        && ("XJ015".equals(se.getSQLState())))) {
                    // we got the expected exception
                    System.out.println("Derby shut down normally");
                    // Note that for single database shutdown, the expected
                    // SQL state is "08006", and the error code is 45000.
                } else {
                    // if the error code or SQLState is different, we have
                    // an unexpected exception (shutdown failed)
                    System.out.println("Derby did not shut down normally");
                    printSQLException(se);
                }
            }
        } catch (SQLException sqle) {
            printSQLException(sqle);
        } finally {
            // release all open resources to avoid unnecessary memory usage
            try {
                if (rs != null) {
                    rs.close();
                    rs = null;
                }
            } catch (SQLException sqle) {
                printSQLException(sqle);
            }

            // Statements and PreparedStatements
            int i = 0;
            while (!statements.isEmpty()) {
                // PreparedStatement extend Statement
                Statement st = (Statement) statements.remove(i);
                try {
                    if (st != null) {
                        st.close();
                        st = null;
                    }
                } catch (SQLException sqle) {
                    printSQLException(sqle);
                }
            }
            //Connection
            try {
                if (conn != null) {
                    conn.close();
                    conn = null;
                }
            } catch (SQLException sqle) {
                printSQLException(sqle);
            }
        }
        return jobnames;
    }

    private void loadDriver() {
        try {
            Class.forName(driver).newInstance();
            System.out.println("Loaded the appropriate driver");
        } catch (ClassNotFoundException cnfe) {
            System.err.println("\nUnable to load the JDBC driver " + driver);
            System.err.println("Please check your CLASSPATH.");
            cnfe.printStackTrace(System.err);
        } catch (InstantiationException ie) {
            System.err.println(
                    "\nUnable to instantiate the JDBC driver " + driver);
            ie.printStackTrace(System.err);
        } catch (IllegalAccessException iae) {
            System.err.println(
                    "\nNot allowed to access the JDBC driver " + driver);
            iae.printStackTrace(System.err);
        }
    }

    private void reportFailure(String message) {
        System.err.println("\nData verification failed:");
        System.err.println('\t' + message);
    }

    public static void printSQLException(SQLException e) {
        // Unwraps the entire exception chain to unveil the real cause of the
        // Exception.
        while (e != null) {
            System.err.println("\n----- SQLException -----");
            System.err.println("  SQL State:  " + e.getSQLState());
            System.err.println("  Error Code: " + e.getErrorCode());
            System.err.println("  Message:    " + e.getMessage());
            // for stack traces, refer to derby.log or uncomment this:
            //e.printStackTrace(System.err);
            e = e.getNextException();
        }
    }
}

NOTICE:  The information contained in this electronic mail transmission is intended by Convergys Corporation for the use of the named individual or entity to which it is directed and may contain information that is privileged or otherwise confidential.  If you have received this electronic mail transmission in error, please delete it from your system without copying or forwarding it, and notify the sender of the error by reply email or by telephone (collect), so that the sender's address records can be corrected.

Re: problem with embedded driver

Posted by Knut Anders Hatlen <kn...@oracle.com>.
steve lescure <st...@yahoo.com> writes:

> thanks for the suggestion. probably a stupid question, but i'll ask anyway.
>
> would the full path be something like 
>
> C:\my_data\NetBeansProjects\On Demand  ?
>
> i see several directories in this location, like
>
> log
> seq0
> tmp 
>
> would i actually put that in the code c:\my_data etc?

The database directory (the one you put in the connection URL) is the
parent directory of log, seg0, tmp. So the "On Demand" directory sounds
like the correct one. When connecting via JDBC in a Java application,
you need to escape the backslashes or replace them by forward slashes.

Something like

    Connection c = DriverManager.getConnection(
            "jdbc:derby:C:\\my_data\\NetBeansProjects\\On Demand");

or

    Connection c = DriverManager.getConnection(
            "jdbc:derby:C:/my_data/NetBeansProjects/On Demand");

should do the trick.

-- 
Knut Anders

RE: problem with embedded driver

Posted by steve lescure <st...@yahoo.com>.
thanks for the suggestion. probably a stupid question, but i'll ask anyway.

would the full path be something like 

C:\my_data\NetBeansProjects\On Demand  ?

i see several directories in this location, like

log
seq0
tmp 

would i actually put that in the code c:\my_data etc?

steve



--- On Wed, 4/20/11, Daniel A Keefe <da...@convergys.com> wrote:

> From: Daniel A Keefe <da...@convergys.com>
> Subject: RE: problem with embedded driver
> To: "Derby Discussion" <de...@db.apache.org>
> Date: Wednesday, April 20, 2011, 7:47 AM
> I have found that I need to include
> the path to the derby db in my connect string
> 
> dk
> 
> ________________________________________
> From: steve lescure [stevelescure@yahoo.com]
> Sent: Tuesday, April 19, 2011 10:36 PM
> To: Derby Discussion
> Subject: Re: problem with embedded driver
> 
> thanks that was a great big help!   never
> would have figured all that out.
> 
> i can now connect to the database............now i've
> encounter yet another mystery.
> 
> It keeps telling me it can't find my table JOBS....i've
> read that NETBEANS should create  a default schema
> NBUSER (the id I used to when i created the db).  When
> i check the properties of the database, the schema is indeed
> NBUSER.  however, to create a table i have to use the
> APP schema (NBUSER is not in the list).  I did that,
> but NETBEANS can't find the table even if i use APP.JOBS...
> I've tried JOBS  APP.JOBS NBUSER.JOBS all fail.
> 
> any thoughts?
> 
>         try {
>             Properties props
> = new Properties(); // connection properties
>             props.put("user",
> "nbuser");
>            
> props.put("password", "nbuser");
>             String dbName =
> "DEMAND"; // the name of the database
> 
>             conn =
> DriverManager.getConnection(protocol + dbName
>                
>     + ";create=false", props);
>            
> System.out.println("Connected to database " + dbName);
> 
>            
> conn.setAutoCommit(true);
>             s =
> conn.createStatement();
>            
> statements.add(s);
>             rs =
> s.executeQuery(
>                
>     "SELECT JOBNAME, USERID FROM APP.JOBS");
>             (dies here)
> 
> 
> 
> 
> 
> 
> --- On Tue, 4/19/11, Mark Eggers <md...@gmail.com>
> wrote:
> 
> > From: Mark Eggers <md...@gmail.com>
> > Subject: Re: problem with embedded driver
> > To: derby-user@db.apache.org
> > Date: Tuesday, April 19, 2011, 4:46 PM
> > On Tue, 19 Apr 2011 12:45:54 -0700,
> > steve lescure wrote:
> >
> > > String dbName = "//localhost:1527/users";
> >
> > This is a connection to the network server. If you
> don't
> > start the
> > database prior to running your program, there will be
> no
> > connection.
> >
> > If you're using the embedded driver, the database name
> is
> > just the name
> > of the database (users, in your case).
> >
> > Now the next problem is that with NetBeans, the
> database
> > gets created in
> > a strange spot - $HOME/.netbeans-derby by default.
> Probably
> > the easiest
> > way to run this program is by passing a value for the
> > derby.system.home
> > property. This tells Derby where to look for databases
> when
> > the program
> > is started.
> >
> > By default, the value is ".". This obviously won't
> work for
> > your code,
> > since you used NetBeans to create the database.
> However,
> > setting this in
> > NetBeans is pretty easy.
> >
> > 1. Right-mouse click on your project and select
> Properties
> > 2. In the dialog box, click on the Run item
> > 3. Add the following to your VM Options:
> >
> > -Dderby.system.home=$HOME/.netbeans-derby
> >
> > You might have to replace $HOME with the full path,
> > depending on how
> > NetBeans handles environment variables.
> >
> > Now the program will run from within NetBeans. When
> you run
> > this from the
> > command line (in the dist folder of your project), use
> the
> > following
> > syntax.
> >
> > java -Dderby.system.home=$HOME/.netbeans-derby -jar
> > YourApp.jar
> >
> > Hope this helps.
> >
> > . . . . just my two cents.
> >
> > /mde/
> >
> >
> 
> NOTICE:  The information contained in this electronic
> mail transmission is intended by Convergys Corporation for
> the use of the named individual or entity to which it is
> directed and may contain information that is privileged or
> otherwise confidential.  If you have received this
> electronic mail transmission in error, please delete it from
> your system without copying or forwarding it, and notify the
> sender of the error by reply email or by telephone
> (collect), so that the sender's address records can be
> corrected.
> 

RE: problem with embedded driver

Posted by Daniel A Keefe <da...@convergys.com>.
I have found that I need to include the path to the derby db in my connect string

dk

________________________________________
From: steve lescure [stevelescure@yahoo.com]
Sent: Tuesday, April 19, 2011 10:36 PM
To: Derby Discussion
Subject: Re: problem with embedded driver

thanks that was a great big help!   never would have figured all that out.

i can now connect to the database............now i've encounter yet another mystery.

It keeps telling me it can't find my table JOBS....i've read that NETBEANS should create  a default schema NBUSER (the id I used to when i created the db).  When i check the properties of the database, the schema is indeed NBUSER.  however, to create a table i have to use the APP schema (NBUSER is not in the list).  I did that, but NETBEANS can't find the table even if i use APP.JOBS... I've tried JOBS  APP.JOBS NBUSER.JOBS all fail.

any thoughts?

        try {
            Properties props = new Properties(); // connection properties
            props.put("user", "nbuser");
            props.put("password", "nbuser");
            String dbName = "DEMAND"; // the name of the database

            conn = DriverManager.getConnection(protocol + dbName
                    + ";create=false", props);
            System.out.println("Connected to database " + dbName);

            conn.setAutoCommit(true);
            s = conn.createStatement();
            statements.add(s);
            rs = s.executeQuery(
                    "SELECT JOBNAME, USERID FROM APP.JOBS");
            (dies here)






--- On Tue, 4/19/11, Mark Eggers <md...@gmail.com> wrote:

> From: Mark Eggers <md...@gmail.com>
> Subject: Re: problem with embedded driver
> To: derby-user@db.apache.org
> Date: Tuesday, April 19, 2011, 4:46 PM
> On Tue, 19 Apr 2011 12:45:54 -0700,
> steve lescure wrote:
>
> > String dbName = "//localhost:1527/users";
>
> This is a connection to the network server. If you don't
> start the
> database prior to running your program, there will be no
> connection.
>
> If you're using the embedded driver, the database name is
> just the name
> of the database (users, in your case).
>
> Now the next problem is that with NetBeans, the database
> gets created in
> a strange spot - $HOME/.netbeans-derby by default. Probably
> the easiest
> way to run this program is by passing a value for the
> derby.system.home
> property. This tells Derby where to look for databases when
> the program
> is started.
>
> By default, the value is ".". This obviously won't work for
> your code,
> since you used NetBeans to create the database. However,
> setting this in
> NetBeans is pretty easy.
>
> 1. Right-mouse click on your project and select Properties
> 2. In the dialog box, click on the Run item
> 3. Add the following to your VM Options:
>
> -Dderby.system.home=$HOME/.netbeans-derby
>
> You might have to replace $HOME with the full path,
> depending on how
> NetBeans handles environment variables.
>
> Now the program will run from within NetBeans. When you run
> this from the
> command line (in the dist folder of your project), use the
> following
> syntax.
>
> java -Dderby.system.home=$HOME/.netbeans-derby -jar
> YourApp.jar
>
> Hope this helps.
>
> . . . . just my two cents.
>
> /mde/
>
>

NOTICE:  The information contained in this electronic mail transmission is intended by Convergys Corporation for the use of the named individual or entity to which it is directed and may contain information that is privileged or otherwise confidential.  If you have received this electronic mail transmission in error, please delete it from your system without copying or forwarding it, and notify the sender of the error by reply email or by telephone (collect), so that the sender's address records can be corrected.

Re: problem with embedded driver

Posted by steve lescure <st...@yahoo.com>.
thanks! i'm trying your suggestions right now.  

Is there a book on derby that anybody would recommend?  i'd like to get something that goes beyond the basics..

steve


--- On Wed, 4/20/11, Knut Anders Hatlen <kn...@oracle.com> wrote:

> From: Knut Anders Hatlen <kn...@oracle.com>
> Subject: Re: problem with embedded driver
> To: "Derby Discussion" <de...@db.apache.org>
> Date: Wednesday, April 20, 2011, 3:09 AM
> steve lescure <st...@yahoo.com>
> writes:
> 
> > thanks that was a great big help! never would have
> figured all that
> > out.
> >
> > i can now connect to the database............now i've
> encounter yet
> > another mystery.
> >
> > It keeps telling me it can't find my table
> JOBS....i've read that
> > NETBEANS should create a default schema NBUSER (the id
> I used to when
> > i created the db). When i check the properties of the
> database, the
> > schema is indeed NBUSER. however, to create a table i
> have to use the
> > APP schema (NBUSER is not in the list). I did that,
> but NETBEANS can't
> > find the table even if i use APP.JOBS... I've tried
> JOBS APP.JOBS
> > NBUSER.JOBS all fail.
> >
> > any thoughts?
> >
> >  
> >         try {
> >         
>    Properties props = new Properties(); //
> connection properties
> >         
>    props.put("user", "nbuser");
> >         
>    props.put("password", "nbuser");
> >         
>    String dbName = "DEMAND"; // the name of
> the database
> >
> >         
>    conn =
> DriverManager.getConnection(protocol + dbName
> >               
>      + ";create=false", props);
> >         
>    System.out.println("Connected to database
> " + dbName);
> >
> >         
>    conn.setAutoCommit(true);
> >             s
> = conn.createStatement();
> >         
>    statements.add(s);
> >             rs
> = s.executeQuery(
> >               
>      "SELECT JOBNAME, USERID FROM
> APP.JOBS");
> >         
>    (dies here) 
> 
> Did you set derby.system.home to ~/.netbeans-derby for your
> application.
> If you didn't, the code above will connect to a database in
> the current
> working directory (if there is one with that name) instead
> of the
> database in ~/.netbeans-derby.
> 
> Alternatively, you can specify the full path to the
> database in the
> connection URL:
> 
>   jdbc:derby:/home/steve/.netbeans-derby/DEMAND
> 
> If you've already done this and it doesn't work, you could
> make your
> application print all your tables and which schema they're
> in by
> changing your query to:
> 
>     rs = s.executeQuery(
>         "select schemaname || '.' ||
> tablename from " +
>         "sys.systables t,
> sys.sysschemas s " +
>         "where t.schemaid=s.schemaid
> and schemaname not like 'SYS%'");
>     System.out.println("Tables:");
>     while (rs.next()) {
>        
> System.out.println(rs.getString(1));
>     }
> 
> -- 
> Knut Anders
> 

Re: problem with embedded driver

Posted by Knut Anders Hatlen <kn...@oracle.com>.
steve lescure <st...@yahoo.com> writes:

> thanks that was a great big help! never would have figured all that
> out.
>
> i can now connect to the database............now i've encounter yet
> another mystery.
>
> It keeps telling me it can't find my table JOBS....i've read that
> NETBEANS should create a default schema NBUSER (the id I used to when
> i created the db). When i check the properties of the database, the
> schema is indeed NBUSER. however, to create a table i have to use the
> APP schema (NBUSER is not in the list). I did that, but NETBEANS can't
> find the table even if i use APP.JOBS... I've tried JOBS APP.JOBS
> NBUSER.JOBS all fail.
>
> any thoughts?
>
>  
>         try {
>             Properties props = new Properties(); // connection properties
>             props.put("user", "nbuser");
>             props.put("password", "nbuser");
>             String dbName = "DEMAND"; // the name of the database
>
>             conn = DriverManager.getConnection(protocol + dbName
>                     + ";create=false", props);
>             System.out.println("Connected to database " + dbName);
>
>             conn.setAutoCommit(true);
>             s = conn.createStatement();
>             statements.add(s);
>             rs = s.executeQuery(
>                     "SELECT JOBNAME, USERID FROM APP.JOBS");
>             (dies here) 

Did you set derby.system.home to ~/.netbeans-derby for your application.
If you didn't, the code above will connect to a database in the current
working directory (if there is one with that name) instead of the
database in ~/.netbeans-derby.

Alternatively, you can specify the full path to the database in the
connection URL:

  jdbc:derby:/home/steve/.netbeans-derby/DEMAND

If you've already done this and it doesn't work, you could make your
application print all your tables and which schema they're in by
changing your query to:

    rs = s.executeQuery(
        "select schemaname || '.' || tablename from " +
        "sys.systables t, sys.sysschemas s " +
        "where t.schemaid=s.schemaid and schemaname not like 'SYS%'");
    System.out.println("Tables:");
    while (rs.next()) {
        System.out.println(rs.getString(1));
    }

-- 
Knut Anders

Re: problem with embedded driver

Posted by steve lescure <st...@yahoo.com>.
thanks that was a great big help!   never would have figured all that out. 

i can now connect to the database............now i've encounter yet another mystery.  

It keeps telling me it can't find my table JOBS....i've read that NETBEANS should create  a default schema NBUSER (the id I used to when i created the db).  When i check the properties of the database, the schema is indeed NBUSER.  however, to create a table i have to use the APP schema (NBUSER is not in the list).  I did that, but NETBEANS can't find the table even if i use APP.JOBS... I've tried JOBS  APP.JOBS NBUSER.JOBS all fail.

any thoughts?
 
        try {
            Properties props = new Properties(); // connection properties
            props.put("user", "nbuser");
            props.put("password", "nbuser");
            String dbName = "DEMAND"; // the name of the database

            conn = DriverManager.getConnection(protocol + dbName
                    + ";create=false", props);
            System.out.println("Connected to database " + dbName);

            conn.setAutoCommit(true);
            s = conn.createStatement();
            statements.add(s);
            rs = s.executeQuery(
                    "SELECT JOBNAME, USERID FROM APP.JOBS");
            (dies here) 






--- On Tue, 4/19/11, Mark Eggers <md...@gmail.com> wrote:

> From: Mark Eggers <md...@gmail.com>
> Subject: Re: problem with embedded driver
> To: derby-user@db.apache.org
> Date: Tuesday, April 19, 2011, 4:46 PM
> On Tue, 19 Apr 2011 12:45:54 -0700,
> steve lescure wrote:
> 
> > String dbName = "//localhost:1527/users";
> 
> This is a connection to the network server. If you don't
> start the 
> database prior to running your program, there will be no
> connection.
> 
> If you're using the embedded driver, the database name is
> just the name 
> of the database (users, in your case).
> 
> Now the next problem is that with NetBeans, the database
> gets created in 
> a strange spot - $HOME/.netbeans-derby by default. Probably
> the easiest 
> way to run this program is by passing a value for the
> derby.system.home 
> property. This tells Derby where to look for databases when
> the program 
> is started.
> 
> By default, the value is ".". This obviously won't work for
> your code, 
> since you used NetBeans to create the database. However,
> setting this in 
> NetBeans is pretty easy.
> 
> 1. Right-mouse click on your project and select Properties
> 2. In the dialog box, click on the Run item
> 3. Add the following to your VM Options:
> 
> -Dderby.system.home=$HOME/.netbeans-derby
> 
> You might have to replace $HOME with the full path,
> depending on how 
> NetBeans handles environment variables.
> 
> Now the program will run from within NetBeans. When you run
> this from the 
> command line (in the dist folder of your project), use the
> following 
> syntax.
> 
> java -Dderby.system.home=$HOME/.netbeans-derby -jar
> YourApp.jar
> 
> Hope this helps.
> 
> . . . . just my two cents.
> 
> /mde/
> 
> 

Re: problem with embedded driver

Posted by Mark Eggers <md...@gmail.com>.
On Tue, 19 Apr 2011 12:45:54 -0700, steve lescure wrote:

> String dbName = "//localhost:1527/users";

This is a connection to the network server. If you don't start the 
database prior to running your program, there will be no connection.

If you're using the embedded driver, the database name is just the name 
of the database (users, in your case).

Now the next problem is that with NetBeans, the database gets created in 
a strange spot - $HOME/.netbeans-derby by default. Probably the easiest 
way to run this program is by passing a value for the derby.system.home 
property. This tells Derby where to look for databases when the program 
is started.

By default, the value is ".". This obviously won't work for your code, 
since you used NetBeans to create the database. However, setting this in 
NetBeans is pretty easy.

1. Right-mouse click on your project and select Properties
2. In the dialog box, click on the Run item
3. Add the following to your VM Options:

-Dderby.system.home=$HOME/.netbeans-derby

You might have to replace $HOME with the full path, depending on how 
NetBeans handles environment variables.

Now the program will run from within NetBeans. When you run this from the 
command line (in the dist folder of your project), use the following 
syntax.

java -Dderby.system.home=$HOME/.netbeans-derby -jar YourApp.jar

Hope this helps.

. . . . just my two cents.

/mde/