How do I run the database program outside the Netbeans IDE?

I am really new to database and this is my first program in database using java Netbeans 7.1 --- It is summer in our country and I am a student with IT course Our next programming question is about database and since there is no class I I spend my time studying the database in preparation for the next high school semester and I am referring to this site as a guide for the first database program I am doing now.

http://www.homeandlearn.co.uk/java/databases_and_java_forms.html

I did everything in the tutorial and I actually did the program.

The last thing I did was clean and build the program as I want the program to start without opening the cells again. I downloaded the JRE and made my database_form.jar file executable. "database_form" is the name of my Netbeans project. I do this by making javaw in JRE.7 as my dafault when opening any jar files.

Anyway, this is how I run the program.

  • Current program in NetBeans IDE

Using Netbeans, before my program works, I first need to "Start Server" in JavaDB. because if i didn't do that, the exception "Err. connecting to server localhost 1527, etc."

  • Run the program using only the jar executable.

The problem is that there was still an exception and Err.

What do I want to achieve?

I want the program to start without opening Netbeans IDE and going to Java DB to click Start Server, I don't want to do that anymore. Or my second option is to start the server using command line, so I just need to make a bat file so that whenever I open my database_form.jar program, I just put the bat file on my desktop and run it.

Second problem! In fact, I already tried my second option, using the command line to start the server, but I forgot how I did it, I just found it on some website, the only thing I remember is the exception: " Failed to dine on the server because the Employees database is missing Employees is the name of my created database.

The OS I am using Windows 7.

Thanks for the whole answer and sorry for the long text, I just want to be specific: D

+3


source to share


3 answers


That's right, from your description there seems to be a few things that you are misleading.

First, databases usually run as servers with multiple clients connecting to them, allowing them to be shared. When you start Java DB, you start the Java DB database server.

However, lightweight databases like Java DB can be run in inline mode as described here . Remember that the directory you point to the property derby.system.home

must contain the database files unless you also need to create this programmatically.

Secondly, there are various ways to run a Java application outside of the IDE, but the jars themselves are not executed in the same way as the exe file is in Windows.

The easiest way is to call the java executable passing the required classpath and the name of the class containing the main method. For example, if I had a named class com.example.Application

that was compiled into a directory C:\dev\example\classes

, the following command started the application:

java -cp C:\dev\example\classes com.example.Application

      

If there were dependencies on external libraries, as would in your case on the Derby JDBC driver, then they would also need to be included in the classpath, which would lead to something like:



java -cp C:\dev\example\classes;C:\dev\lib\derby.jar com.example.Application

      

There is a complete set of Java launcher docs here.

Now back to the bank. As I said, banks are not executable, but there is something that is known as "bank executable". This is the same as any jar, except that there are some special additions in the manifest to specify the application entry point or main class and classpath as described here .

Once the main class and class-path are specified in the jar manifest, the following command will launch the application:

java -jar C:\dev\example.jar

      

You can even link the jar extension to the java exe, and double clicking on the jar will launch the application (although on a dev machine it is probably more useful to have the jar extension linked to WinZip or simlar to open that jar).

+2


source


The default database in Netbeans is Derby / JavaDB. Therefore, you need:

  • add the javadb / derby jar to our classpath (it might already be there as it is associated with java when you install it on Ubuntu)
  • configure path using jdbc URI to save database data.


I personally recommend using hsqldb or H2 for this: they maintain an in-memory database very useful for a stand-alone project without persistence data or for tests.

0


source


If you are using a window, add ODBC data sources from administrative tools to your Java Derby driver and run the jar.

0


source







All Articles