Results 1 to 9 of 9
  1. #1
    edi.gotieb is offline Member
    Join Date
    Apr 2010
    Posts
    12
    Rep Power
    0

    Exclamation derby DB problem

    Ive lately tried doing some stuff with Java data bases. im using derby.
    i created a data base through NB and added a testing table.
    i tried to create a connection to that DB through java code- but evrey time when it reaches the connection statement it throws an exception:
    Java Code:
    java.sql.SQLNonTransientConnectionException: java.net.ConnectException : Error connecting to server localhost on
     port 1527 with message Connection refused: connect.
    the weird thing is that if i connect to the db via the services window and then disconnect, before i start the java code- it works.
    i did add the derby and derbyclient jar's to my libraries.
    here is some of my code:

    Java Code:
     Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
    Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/TestDB","edi123","edi123");
    java.sql.Statement stmt =  con.createStatement();
    try {
           ResultSet rs = stmt.executeQuery("SELECT * FROM App.TestCreate");
            while (rs.next()) {
            String n = rs.getString("Name");
            String p = rs.getString   ("UserName");
            System.out.println(n + "   " + p);
            }}
    catch(Exception e) {
        e.printStackTrace();
        System.out.println(e.getMessage());
            System.exit(0);
    } }}
    does anybody have any idea as to what could be causing this weird problem?
    thanks
    Edi
    Last edited by edi.gotieb; 05-16-2010 at 08:52 PM.

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,771
    Blog Entries
    7
    Rep Power
    21

    Default

    What happens when you try to open a connection to "jdbc:derby:<your database>"? i.e. you are using an embedded driver so there is no use to specifying a host and port number.

    kind regards,

    Jos

  3. #3
    edi.gotieb is offline Member
    Join Date
    Apr 2010
    Posts
    12
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    so there is no use to specifying a host and port umber.
    what exactly does it mean that i dont need host and prot number? can i just put the directory straight in?

    as i specified in my post when i try to connect i get the exception and the message posted above.

    thanks for your reply.

    Edi

  4. #4
    edi.gotieb is offline Member
    Join Date
    Apr 2010
    Posts
    12
    Rep Power
    0

    Default

    i just tried to run with your suggestion and it worked!
    thanks a lot!
    i'de be glad if you can elaborate on what an embedded driver means?
    thanks
    Edi

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,771
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by edi.gotieb View Post
    what exactly does it mean that i dont need host and prot number? can i just put the directory straight in?

    as i specified in my post when i try to connect i get the exception and the message posted above.

    thanks for your reply.

    Edi
    Just as I wrote: an embedded driver can only make connections to the db on the same machine so a url "jdbc:derby:TestDB" should be enough. Did you give it a try?

    kind regards,

    Jos

  6. #6
    edi.gotieb is offline Member
    Join Date
    Apr 2010
    Posts
    12
    Rep Power
    0

    Default

    i did! and it works! thanks very much.

  7. #7
    edi.gotieb is offline Member
    Join Date
    Apr 2010
    Posts
    12
    Rep Power
    0

    Default

    hi-
    im having a different issue now.
    when i creat a database through NB it automatically sets the URL and driver-
    to the client driver- and the URL with the host and port.
    NB manages to connect to the db when i just leave it but when i change the properties to the ones you showed me (i.e no host and port+ embeeded driver)
    NB is unable to connect to the DB.
    other then that- what effect does the driver choosing have on the db?
    i mean: the data base is the same no matter what driver i use?
    + why is it unable to connect via the IDE but is able in the exact same fashion through the java code?

    thanks
    Edi

  8. #8
    edi.gotieb is offline Member
    Join Date
    Apr 2010
    Posts
    12
    Rep Power
    0

    Default

    i solved the problem but would like answers to the questions about databases. :):D

  9. #9
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,771
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by edi.gotieb View Post
    i solved the problem but would like answers to the questions about databases. :):D
    This is ripped straight from the JavaDB documents (you have them installed too if you have Java 1.6 SE installed):

    Quote Originally Posted by JavDB docs
    Embedded environment
    An embedded environment is an environment in which only a single application can access a database at one time, and no network access occurs.

    When an application starts an instance of Derby within its JVM, the application runs in an embedded environment. Loading the embedded driver starts Derby.
    for the other driver this is what those docs have to say:

    Client/server environment
    A client/server environment is an environment in which multiple applications connect to Derby over the network.

    Derby runs embedded in a server framework that allows multiple network connections. (The framework itself starts an instance of Derby and runs in an embedded environment. However, the client applications do not run in the embedded environment.)

    You can also embed Derby in any Java server framework.

    See the Java DB Server and Administration Guide for more information on how to run Derby on a server.
    I don't know NetBeans so I don't know why it failed to configure your database driver.

    kind regards,

    Jos

Similar Threads

  1. Replies: 1
    Last Post: 05-11-2010, 11:31 AM
  2. need some derby tips:
    By kulangotski in forum Advanced Java
    Replies: 4
    Last Post: 03-09-2009, 06:09 PM
  3. procedures in derby
    By suhaib1thariq in forum JDBC
    Replies: 0
    Last Post: 01-31-2009, 06:39 PM
  4. using if in derby
    By suhaib1thariq in forum JDBC
    Replies: 0
    Last Post: 01-25-2009, 05:46 AM
  5. Is there a problem with Derby?
    By orion_mcl in forum Advanced Java
    Replies: 0
    Last Post: 08-10-2007, 05:35 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •