How to run database program outside the Netbeans IDE?

后端 未结 3 1699
天涯浪人
天涯浪人 2021-01-20 15:30

I am really new to database and this is my first program in database using java Netbeans 7.1 --- It is summer on our country now and I am a student with the course I.T. Our

相关标签:
3条回答
  • 2021-01-20 15:52

    The default database in Netbeans is Derby/JavaDB. So you need to:

    • add the jar of javadb/derby in our classpath (it maybe already present, as it is bundled with java when you install it in Ubuntu)
    • setup a path with the jdbc URI to save the database data

    I personally recommend the usage of hsqldb or H2 for this: they support in-memory database, very useful for stand alone project with no persistence data or for tests.

    0 讨论(0)
  • 2021-01-20 15:55

    If you use window, add ODBC Data Sources from Administrative Tools to your Java Derby driver and run jar.

    0 讨论(0)
  • 2021-01-20 16:04

    Right, from your description there seems to be a couple of things you are confusing.

    First, databases are typically run as servers with multiple clients connecting to them thus allowing they contain to be shared. When you start Java DB you are starting the Java DB database server.

    That said, lightweight databases, such as Java DB can be run in an embedded mode as explained here. Remember that the directory you point to with the derby.system.home property will need to contain the database files, if not you'll need to create that programatically too.

    Second, there's various ways to run a Java application outside of an IDE, but jars themselves are not executable in the same way an exe file is in Windows.

    The simplest way is to call the java executable passing the necessary classpath and the name of the class containing the main method. For example if I had a class called com.example.Application that had been compiled to a directory C:\dev\example\classes the following command line would run the application:

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

    If there were dependencies on external libraries, as there will be in your case on the Derby JDBC driver, then those would also need including in the classpath resulting in something like:

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

    There's a full set of document on the Java launcher here.

    Now, back to the jar. Like I said, jars are not executable but there is something that's know as an 'executable jar'. This is the same as any jar except there are some special additions to the manifest to specify the application entry point or main-class and the class-path as described here.

    Once the main-class and class-path are specified in the jar's manifest, the following command line would run the application:

    java -jar C:\dev\example.jar
    

    You can even associate the jar extension with the java exe and double clicking the jar will cause the application to launch (though on a dev machine it's probably more useful that the jar extension be associated with WinZip or simlar in order to open that jar).

    0 讨论(0)
提交回复
热议问题