简体   繁体   English

通过命令提示符运行的JDBC Java文件

[英]JDBC Java File Running Through Command Prompt

I have created a java gui within Netbeans and am now attempting to run it through Command Prompt using the java -jar [filename].jar command. 我已经在Netbeans中创建了一个Java gui,现在正尝试使用java -jar [filename].jar命令通过命令提示符运行它。

The gui I have created connects to a database (also created within the Servers section of Netbeans). 我创建的GUI连接到数据库(也在Netbeans的“服务器”部分中创建)。 The database is connected to view the jdbc:derby://localhost:1527/[DBName] command. 已连接数据库以查看jdbc:derby://localhost:1527/[DBName]命令。 It also takes in the user name and password and then connects. 它还输入用户名和密码,然后进行连接。

My issue is, I can connect within Netbeans (obviously I have to find the database in the Services tab first and connect to it) but I can't connect to the database in command prompt. 我的问题是,我可以在Netbeans中进行连接(显然,我必须先在“服务”选项卡中找到该数据库并进行连接),但是我无法在命令提示符下连接至该数据库。

With the completed code I have selected 'Clean and Build' in Netbeans to create the .jar file in the /dist folder. 使用完成的代码,我在Netbeans中选择了“清理并生成”以在/ dist文件夹中创建.jar文件。

I can run the .jar file but it returns an error stating: java.net.ConnectionException : Error connecting to server localhost on port 1527 with message Connection refused: connect. 我可以运行.jar文件,但它返回一个错误,指出: java.net.ConnectionException : Error connecting to server localhost on port 1527 with message Connection refused: connect.

My /dist folder contains the .jar file for the application as well as a README.TXT file and a /lib folder, which itself contains the derbyclient.jar file. 我的/ dist文件夹包含该应用程序的.jar文件以及README.TXT文件和/ lib文件夹,该文件夹本身包含derbyclient.jar文件。

When creating my database I set the location as the java project directory so within the java project directory I have a /[DBName] folder that I assume contains my database. 创建数据库时,我将位置设置为java项目目录,因此在java项目目录中,我有一个/ [DBName]文件夹,我认为其中包含我的数据库。

How do I connect to the database in command prompt? 如何在命令提示符下连接到数据库? Or at least allow my program to do so? 或者至少允许我的程序这样做?

Do I have to explicitly declare the location of my database? 我是否必须明确声明数据库的位置?

Do I need to export the database from Netbeans somehow? 我是否需要以某种方式从Netbeans导出数据库?

Any help would be great. 任何帮助都会很棒。 I'm toying with Java at the moment and wanted to know how to run it in command prompt, completely standalone from any IDE's. 我现在正在玩Java,想知道如何在命令提示符下运行它,而这完全独立于任何IDE。

J Ĵ

Derby has a command line client called ij that you can use to type SQL commands. Derby有一个名为ij的命令行客户端,可用于键入SQL命令。 If you are using the derby that is built into the java distribution then you need to look under JAVA_HOME/db/bin and you will find a lot of .sh and .bat files to start up the derby server, 如果您使用的是Java发行版中内置的derby,则需要查看JAVA_HOME / db / bin,您会发现很多.sh和.bat文件来启动derby服务器,

NetworkServerControl     derby_common.bat         setEmbeddedCP.bat        setNetworkServerCP.bat   stopNetworkServer.bat
NetworkServerControl.bat ij                       setNetworkClientCP       startNetworkServer       sysinfo
dblook                   ij.bat                   setNetworkClientCP.bat   startNetworkServer.bat   sysinfo.bat
dblook.bat               setEmbeddedCP            setNetworkServerCP       stopNetworkServer

so look at those files and read the docs for the java derby db to see how to start it. 因此,请查看这些文件并阅读Java derby db的文档以了解如何启动它。 Calling startNetworkServer will start derby as a network server on port 1527. 调用startNetworkServer将在端口1527上将derby作为网络服务器启动。

http://db.apache.org/derby/ contains a lot of docs on derby. http://db.apache.org/derby/包含有关derby的许多文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM