`

NetBeans Derby Tutorial

    博客分类:
  • Java
阅读更多

Derby Tutorial

Tutorial Prep

This demo requires NetBeans 5.0 RC1 or later.
  1. Download and install NetBeans 5.0.

Tutorial

Get the Derby Database

  1. Download the latest official Derby release (10.1.2.1 at the time of this writing).
  2. Extract the archive
  3. In the derby root directory (db-derby-10.1.2.1-bin), create a new folder, database.

Configure the Derby Database in NetBeans

  1. Select Tools > Options (NetBeans > Preferences on the Macintosh) and click the Advanced Options button. Expand the IDE Configuration > Server and External Tools Settings nodes and select the Derby Database node.
  2. Set the Derby Location to where you extracted the Derby archive (e.g., D:\db-derby-10.1.2.1-bin)
  3. Set the Database Location to the location of the database folder created above (e.g., D:\db-derby-10.1.2.1-bin\database) and close the Options dialog.

Start the Derby Server and Create a Database

  1. Select Tools > Derby Database > Start Derby Server. You'll see the following in the output window:


  2. Select Tools > Derby Database > Create Derby Database...
  3. Set the Database Name to Sample. Set the User Name and Password to nbuser.


  4. Switch to the Runtime tab (Ctrl + 5) and expand the Databases node to see your new database


  5. Right-click the Sample database and choose connect.

Adding a Table to the Database

Obviously, since the database is brand new, it's empty. Let's explore the options for adding tables and data.

Create Table Wizard
  1. Expand the Sample database node, right-click the Tables entry and choose Create Table...


  2. Give the table a name, add some columns and set their size. For example:


  3. Right-click the new table and choose Execute Command ...



    This will open a SQL editor which we can use to add some data.
  4. Enter an Insert command, such as:


  5. Press Ctrl+Shift+E to execute the SQL commdand.


  6. Then right-click the table again and choose View Data.... You'll see the select SQL command and the result:



Recreate Table Wizard

This wizard's handy if you have a table in another database that you'd like to recreate in Derby. For this example, I'm using the Pointbase database that comes with the J2EE 1.4 SDK. See the J2EE Quick Start Guide for information on configuring the J2EE 1.4 SDK with NetBeans.
  1. Connect to the Pointbase Sample database (the password is pbpublic). Expand the Tables node. Right-click the SALES_REP_TBL and choose Grab Structure.... Then Save the grab file to some location on disk.


  2. Right-click the Tables node under the Derby Sample database and choose Recreate Table...
  3. Open the SALES_REP_TBL.grab file you saved above.


  4. At this point you can change the table name or edit the create script. For our exercise, just click OK to create the table and you'll see the new table under the Tables node:

Using a SQL Script

Probably the most popular way to manage your database. Unfortunately, the SQL editor in NetBeans only accepts a single command at a time. Issue 68844 has been opened to address this limitation.

So our alternative is to use the ij tool that comes with the Derby database. The easiest way to work with this tool is to create a wrapper script. For example, on Windows, I created the following ij.bat file in my Windows directory (so it would automatically be on the path):

  @echo off
  rem -- Run Derby ij --
  set LIBPATH=D:\db-derby-10.1.2.1-bin\lib
  java -classpath "%LIBPATH%\derbytools.jar;%LIBPATH%\derby.jar;%LIBPATH%\derbyclient.jar" org.apache.derby.tools.ij %1
  

Now, from anywhere on the system, I can call ij against a sql script. For example, Customer.sql will create three tables and populate them with data.

Now return to NetBeans, right-click the Tables entry and choose Refresh to see the 3 new tables. Right-click the CUSTOMER_TBL and choose View Data... to see the table contents. NetBeans puts the SQL statement in the SQL editor and executes it, producing the following results:

You can use the SQL Editor to execute a different SQL statement. For example:

Next Steps

You have now completed the NetBeans Derby Database tutorial. For more information on working with Java GUI's in the NetBeans IDE, see:

分享到:
评论

相关推荐

    Java Homework Projects A NetBeans GUI Swing Programming Tutorial(8th) epub

    Java Homework Projects A NetBeans GUI Swing Programming Tutorial(8th) 英文epub 第8版 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除

    netbeans tutorial

    ### NetBeans 教程:创建基于 JSF 的 CRUD 应用程序 在本教程中,我们将详细介绍如何使用 NetBeans 集成开发环境 (IDE) 创建一个与后端数据库交互的 Web 应用程序。该应用程序将具备查看、修改数据库中的数据的能力...

    NetBeans Selection Management Tutorial I—Using a TopComponent's Lookup

    在本文中,我们将深入探讨NetBeans IDE中的"Selection Management",特别是如何利用TopComponent的Lookup功能。NetBeans 8.0 提供了一种强大的机制,允许开发者管理用户界面中的选择内容,这在创建复杂的集成开发...

    netbeans连接数据库

    ### NetBeans连接数据库知识点详解 #### 一、配置数据库连接池 在NetBeans中实现数据库连接,首先需要配置一个数据库连接池。连接池是管理数据库连接的重要机制,它能够提高应用性能并有效管理资源。 **步骤1:...

    Ubuntu配置Netbeans8.2

    Ubuntu 配置 Netbeans 8.2 Ubuntu 是一个流行的 Linux 发行版,而 Netbeans 是一个功能强大的集成开发环境(IDE)。在本文中,我们将指导您如何在 Ubuntu 20.04 上配置 Netbeans 8.2。 标题解释 Ubuntu 配置 ...

    NetBeans IDE 6.0 Java Quick Start Tutorial

    **标题与描述解读:** "NetBeans IDE 6.0 Java Quick Start Tutorial",即“NetBeans IDE 6.0 Java 快速入门教程”,旨在为初学者提供一个快速了解和上手NetBeans集成开发环境(IDE)的方法,通过创建一个简单的...

    netbeans字体配置文件.netbeans字体配置文件

    netbeans字体配置文件.netbeans字体配置文件netbeans字体配置文件.netbeans字体配置文件netbeans字体配置文件.netbeans字体配置文件netbeans字体配置文件.netbeans字体配置文件netbeans字体配置文件.netbeans字体...

    NetBeans 教程(如何使用NetBeans)

    NetBeans是一款功能强大的开源集成开发环境(IDE),尤其适合Java编程。这个教程将带你深入了解如何有效地使用NetBeans来编译和运行Java程序。NetBeans以其直观的用户界面、丰富的特性集以及对Java SE、Java EE和...

    Java Homework Projects A NetBeans GUI Swing Programming Tutorial(8th) azw3

    Java Homework Projects A NetBeans GUI Swing Programming Tutorial(8th) 英文azw3 第8版 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除

    NetBeans安装包.rar

    NetBeans是一款广泛使用的开源集成开发环境(IDE),尤其在Java编程领域中深受开发者喜爱。它提供了丰富的功能,包括代码编辑、调试、构建和部署等,为开发者提供了高效的工作环境。这个"NetBeans安装包.rar"文件是...

    Apache-NetBeans 21

    Apache-NetBeans 21安装包

    netbeans的Sublime样式

    NetBeans是一款广泛使用的开源集成开发环境(IDE),尤其在Java开发者中颇受欢迎。它提供了丰富的功能,包括代码编辑、调试、构建以及项目管理等。在追求个性化和提高工作效率的现代编程环境中,编辑器的外观和感觉...

    NetBeans权威指南 源码

    NetBeans是当前市场上最为流行的、源代码开放且免费的集成开发环境。NetBeans不仅可以作为Java开发工具,还可以使用它开发标准的Java程序、Web应用程序、Java EE企业级应用程序、Java ME手机应用程序等,还能够开发...

    netbeans安装包

    NetBeans是一款广受欢迎的开源集成开发环境(IDE),专为编程者提供了一个高效、便捷的平台,用于构建桌面、移动和Web应用程序。它的主要特点包括免费性、丰富的语言支持、可扩展性以及对不同操作系统和版本的兼容性...

    netbeans-8.0-linux

    NetBeans IDE 8.0 for Linux 是一个专为开发人员设计的强大集成开发环境(IDE),尤其适用于编写Java应用程序。此版本特别针对Linux操作系统进行了优化,提供了丰富的功能集,旨在提高在Linux平台上的开发效率。 ...

    NetBeans中添加背景图片附源码

    在NetBeans中添加背景图片是一项常见的个性化设置任务,可以让你的开发环境更加独特且符合个人审美。NetBeans是一个流行的开源集成开发环境(IDE),支持多种编程语言,如Java、C++、PHP等。通过自定义背景图片,...

    netbeans-8.2,Linux,x64

    NetBeans IDE 8.2是Java开发环境中的一款强大工具,同时也支持C++和其他多种编程语言。这个版本专为Linux操作系统设计,适用于64位架构。在Linux环境下,开发者经常使用NetBeans来创建、调试和部署应用程序,因为它...

    NetBeans Java快速入门

    NetBeans Java 快速入门指南 本指南提供了使用 NetBeans IDE 创建 Java 控制台应用程序的步骤指南,涵盖了项目创建、编译和运行等基本步骤。通过这篇指南,读者将学习如何使用 NetBeans IDE 创建、编译和运行 Java ...

    NETBEANS做的WEB登录页面

    【NETBEANS做的WEB登录页面】是一个基础的Web开发教程,特别适合NETBEANS的新手。NETBEANS是一款流行的开源集成开发环境(IDE),广泛用于Java、PHP、HTML5等Web开发。它提供了丰富的功能,如代码编辑、调试、版本...

Global site tag (gtag.js) - Google Analytics