Netbeans德比嵌入式错误 [英] Netbeans derby embedded error

查看:65
本文介绍了Netbeans德比嵌入式错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个带有数据库的GUI Alp.我的嵌入式连接有问题.我在服务"选项卡>驱动程序">"Java DB(嵌入式)"中建立了此嵌入式连接,并使用进行连接.我输入数据如下:

I have created a GUI alp with a database. I have a problem with the Embedded connection. I made this Embedded connection in Services tab > drivers > Java DB (Embedded) and connect using. I enter the data as follows:

; create = true是我写的,因为它通常不会在app文件夹中创建数据库文件夹.我创建了一个表,然后将该URL放入了代码con = DriverManager.getConnection

;create=true is what I write because it generally will not create a database folder in the app folder. I create a table and I put that URL in jer the code con = DriverManager.getConnection

当我启动应用程序并在应填写此数据库的各个字段中输入数据时,出现以下错误:java.-sql.SQLSyntaxErrorException:表/视图'nameTable'不存在!

When I start the app and when I enter the data in the respective fields that should fill in this database, the following error appears: java.-sql.SQLSyntaxErrorException: Table/View 'nameTable' does not exists!

我首先将derby.jar驱动程序添加到库中,然后添加了Netbeans随附的Java DB驱动程序,但错误仍然存​​在.无论我做什么,都会出现相同的错误.

I first added derby.jar driver to the library and then I added Java DB driver which comes with Netbeans, but the error remains. The same error appears no matter what I do.

这里是一个代码:

private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                               
   try {     Connection con;

            Connection db = null;

        con = DriverManager.getConnection("jdbc:derby:testBase;create=true ", "app", "admin77");

        Statement stmt = con.createStatement();
        String Query ="INSERT  INTO LINGU (NAME , CONCTRACTNO , EMAIL , PHONE , VIBER ) VALUES ('"+fNameLname.getText()+"' , '"+contTxt.getText()+"' , '")
        stmt.execute(Query);

       JOptionPane.showMessageDialog(null,"You have successfully added this vendor to the list of Lingu vendors.");

        fNameLname.setText(null);
        contTxt.setText(null);
        emailTxT.setText(null);
        phoneTxT.setText(null);
        viberBox.setSelectedIndex(0);
    }     
    catch(SQLException ex){
        JOptionPane.showMessageDialog(null, ex.toString());
    }
}                                       

表格:

推荐答案

使用诸如 jdbc:derby:testBase; create = true 之类的JDBC连接URL,您正在告诉Derby访问名为 testBase ,该文件位于名为 testBase 的文件夹中,相对于您运行程序时的当前工作目录.

With a JDBC Connection URL like jdbc:derby:testBase;create=true, you are telling Derby to access a database named testBase, which is to be found in a folder named testBase relative to whatever is the current working directory when you run your program.

而且您还告诉Derby,如果在运行程序时,相对于当前工作目录的目录而言,名为 testBase 的文件夹中没有数据库,则Derby应该继续并创建一个新数据库.在该位置的新的空数据库.

And you are also telling Derby that, if there is no database in a folder named testBase relative to whatever is the current working directory when you run your program, Derby should go ahead and create a new fresh empty database in that location.

这种方法很容易使自己感到困惑,因为如果您在一个目录中运行一次该程序,创建一些表并加载一些数据,然后在另一个目录中再次运行该程序,则看起来您的所有表消失了,您所有的数据都消失了.

This approach makes it easy to confuse yourself, because if you run the program once in one directory, and create some tables and load some data, and then run the program again in a different directory, it will seem like all your tables have vanished and all your data is gone.

(不是,只是您现在已经创建了两个不同数据库,并且对于使用哪个数据库以及程序的哪个运行感到困惑.)

(It isn't, it's just that you've now created two different databases, and you're confused about which database you're using with which run of your program.)

请注意,从Derby的角度来看,NetBeans IDE只是使用Derby的另一个程序,而NetBeans IDE本身具有其自己的当前工作目录",并且几乎可以肯定是不相同的作为您手动运行程序时使用的当前工作目录.

Note that, from the point of view of Derby, the NetBeans IDE is just another program that is using Derby, and the NetBeans IDE, itself, has its own "current working directory", and it is almost certainly not the same as the current working directory that you use when you run your program by hand.

Derby能够使用相对文件系统路径作为数据库位置,并且能够按需安静地制造新的空数据库( create = true )是非常不错的功能,但它们也可能会造成混乱当您刚开始学习Derby时.

Derby's ability to use relative filesystem paths for database locations, and its ability to quietly manufacture a new empty database on demand (create=true) are very nice features, but they can also be very confusing when you are just starting to learn Derby.

一种相当简单的选择是避免在JDBC连接URL中使用相对的数据库路径名,而始终使用绝对的数据库路径名,例如:

A fairly simple alternative is to avoid using relative database path names in your JDBC Connection URL, and instead always use an absolute database pathname, like:

jdbc:derby:/path/to/my/db/folder/testBase

然后,您会发现您一直在使用同一数据库,并且下次您打开该数据库时,数据将在那里.

Then you will find that you are always using the same database, and your data will be there the next time you go open that database.

这篇关于Netbeans德比嵌入式错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆