本文介绍了如何在Netbeans IDE之外运行数据库程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是数据库的新手,这是我使用java Netbeans 7.1的数据库中的第一个程序---现在我们国家的夏天,我是一名学生。我们关于编程的下一个主题是关于数据库,因为没有课我花时间学习数据库为下一个学期准备,我将这个网站称为我现在制作的第一个数据库程序的指南。

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 next subject on programming is about database and since there's no class I spend my time learning database for preparation for the next school semester and I refer to this site as my guide for the first database program I currently making now.

我在教程中做了一切,实际上我已经完成了这个程序。

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

我做的最后一件事是我清理并构建程序,因为我希望程序运行而不再打开netbeans我下载了JRE并将我的database_form.jar作为jar可执行文件。 database_form我的Netbeans项目的名称。我这样做是通过在打开任何jar文件时将JRE.7中的javaw作为我的dafault来实现的。

The final thing I did is I clean and build the program since I want the program to run with out opening the netbeans again I downloaded the JRE and make my database_form.jar as a jar executable. "database_form" the name of my Netbeans Project. I do that by making javaw in JRE.7 as my dafault when opening any jar files.

无论如何,这是我如何运行该程序。

Anyway, this is how i run the program.


  1. 在正在运行的程序Netbeans IDE

使用Netbeans,在我的程序工作之前,我首先需要在JavaDB上启动服务器。因为如果我没有这样做,则发生异常错误。连接到服务器localhost 1527等等

Using Netbeans, before my program works I first need to "Start Server" on JavaDB. because if I didn't do that an Exception occurred "Err. connecting to server localhost 1527 and so on"


  1. 使用jar可执行文件运行程序单独。

问题是有一个异常,连接中的错误仍然发生。

The Problem is there's an Exception and Err in connecting still occurred.

我想要实现什么?

我希望程序在不打开Netbeans IDE的情况下运行并转到Java DB单击启动服务器,我不想再这样做了。或者我的第二个选择是使用命令提示符来启动服务器,这样我就必须做出一个bat文件,所以,每当我打开我的程序database_form.jar我只是把我的桌面上的bat文件并运行它。

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

第二个问题!
实际上,我已经通过使用命令提示符启动服务器来尝试我的第二个选项,但我忘记了我是如何做到的,我只是在某个网站上发现它我唯一记得的是Exception说无法在服务器上午餐因为数据库的员工缺少,员工是我创建的数据库的名称。

Second Problem!Actually, I already try my second option by using command prompt 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 says "Failed to lunch the server because the database Employees is missing. Employees is the name of my created database.

我使用的操作系统是Windows 7。

The O.S. I am using is Windows 7.

感谢您的回复,对不起我想要具体的长文本,抱歉:D

Thank you for all the reply and sorry for the long text I just want to be specific, :D

推荐答案

右键,从你的描述似乎有几件事情你是混乱的。

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

首先,数据库通常运行与多个客户端连接到他们从而使他们的服务器包含要共享。当你启动Java DB时,你正在启动Java DB数据库服务器。

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.

也就是说,轻量级数据库,例如Java DB,可以在嵌入式中运行解释模式。请记住,您指向与 derby.system.home 财产目录将需要包含数据库文件,如果没有你需要创建一个编程了。

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.

其次,有各种方法可以在IDE之外运行Java应用程序,但jars本身不能像exe文件在Windows中那样执行。

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.

最简单的方法是调用java可执行文件,传递必要的类路径和包含main方法的类的名称。例如,如果我有一个名为 com.example.Application 的类,它已编译到目录 C:\dev\example\classes 以下命令行将运行应用程序:

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

如果存在对外部库的依赖,那么将会有你的情况在德比JDBC驱动程序,那么这些将还需要包括在classpath中造成这样的:

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

Java启动器上有一整套文档。

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

现在,回到罐子里。就像我说的,罐子不是可执行的,但有一些东西被称为可执行jar。这与任何jar都是一样的,除了清单中有一些特殊的附加内容,用于指定应用程序入口点或主类以及所描述的类路径。

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.

一旦在jar的清单中指定了主类和类路径,下面的命令行就会运行应用程序:

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

你甚至可以将jar扩展与java exe相关联,双击jar会导致应用程序启动(虽然在dev机器上,jar扩展与WinZip或simlar相关联可能更有用打开那个罐子。)

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).

这篇关于如何在Netbeans IDE之外运行数据库程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 11:21