6 Replies Latest reply: Jun 5, 2007 8:12 AM by 807606 RSS

    Automatically Connceting to a Derby Database on Startup?

    807606
      is it possible to automatically connect to a database when an application is run, instead of first manually connecting to the database and then running the application?
        • 1. Re: Automatically Connceting to a Derby Database on Startup?
          807606
          is it possible to automatically connect to a database
          when an application is run,
          Yes, your results may vary.

          I don't know what is involved with Derby specifically. What do you mean
          by connect exactly? Do you have a link to some documentation that addresses the need to manually connect as you are talking about?
          • 2. Re: Automatically Connceting to a Derby Database on Startup?
            807606
            What do you mean by connect exactly?
            as in when i press F6 to compile and run my application (using the IDE), a script automatically starts the database that i need to work with. for example: if i want to run my app in NetBeans 5.5 i just press F6. but if i havent started up my database manually yet from the Runtime window i will obviously get a few exceptions because there is no database to connect to because it hasnt been started yet.

            Message was edited by:
            Alex1989
            • 3. Re: Automatically Connceting to a Derby Database on Startup?
              DrClap
              a script automatically starts the database that i need to work with
              Aha. So your problem is not so much that you want to "automatically connect to a database", your problem is that you want to make sure the database server is running before your application tries to connect to it.

              Well, that's not the application's responsibility. It's the database manager's responsibility. That probably means you, in this case. Just start the thing running and let it run forever. If that's too much work (and yes, you should be lazy) then set it up to run as a service, if that's possible, or to run when you login.
              • 4. Re: Automatically Connceting to a Derby Database on Startup?
                807606
                Aha. So your problem is not so much that you want to
                "automatically connect to a database", your problem
                is that you want to make sure the database server is
                running before your application tries to connect to
                it.
                yea
                Well, that's not the application's responsibility.
                It's the database manager's responsibility. That
                probably means you, in this case. Just start the
                thing running and let it run forever.
                my application is a phonebook. i dont think the user would be happy if he/she had to manually start the database each time they wanted to use it.
                If that's too much work (and yes, you should be lazy)
                then set it up to run as a service, if that's possible,
                or to run when you login.
                is there some code in java that allows me to start the server automatically when my app is run. something like this maybe?
                public void startDB(){
                        if(CONTACTS.isStarted() == false){
                            CONTACTS.start();
                        }
                    }
                • 5. Re: Automatically Connceting to a Derby Database on Startup?
                  807606
                  Aha. So your problem is not so much that you want
                  to
                  "automatically connect to a database", your
                  problem
                  is that you want to make sure the database server
                  is
                  running before your application tries to connect
                  to
                  it.
                  yea

                  Well, that's not the application's responsibility.
                  It's the database manager's responsibility. That
                  probably means you, in this case. Just start the
                  thing running and let it run forever.

                  my application is a phonebook. i dont think the user
                  would be happy if he/she had to manually start the
                  database each time they wanted to use it.
                  Derby should exhibit this behaviour as a side-effect of being run in-process with your app. In a typical database application, it's expected that the DBMS will be running constantly, on a server. In your case, running the DBMS in-process should be fine
                  If that's too much work (and yes, you should be
                  lazy)
                  then set it up to run as a service, if that's
                  possible,
                  or to run when you login.
                  is there some code in java that allows me to start
                  the server automatically when my app is run.
                  something like this maybe?
                  public void
                  startDB(){
                  if(CONTACTS.isStarted() == false){
                  CONTACTS.start();
                  }
                  }
                  How are you currently starting Derby? You are running it in the same JVM as your app, aren't you?
                  • 6. Re: Automatically Connceting to a Derby Database on Startup?
                    807606
                    yea i just go to the runtime window and right click on my database (CONTACTS) and click connect