Database Support and Derby Integration


When an instance of Sun Java System Application Server 8.2 is registered within NetBeans IDE, the Derby database is registered as well, and the IDE provides a new set of menu items to start and stop the database or even create a new database. If you are not using the Sun Java System Application Server, it is still possible to manually register the Derby Database via the Tool | Options menu. Navigate in the Advanced Options and select the Derby Database node, as seen in Figure 13-38, where you can enter the Derby installation location and the location where Derby will store the databases.

Figure 13-38. Derby Database Options


If Derby Database is correctly registered in the IDE, the Derby menu is available as a submenu of the Tools Menu, as seen in Figure 13-39.

Figure 13-39. Derby Database menu


Once a database is registered in the IDE, you can create new databases or explore the structure of existing databases in the Runtime window and execute SQL statements using the SQL command editor (see Figure 13-40). You can access the SQL editor by right-clicking the node of a database table and choosing Execute Command.

Figure 13-40. SQL Query editor and executor


In NetBeans IDE 5.0, it is not possible to type more than a single line of SQL code. (This limitation will be fixed in the next version of NetBeans IDE.) However, you can use the ij tool that comes with the Derby database to execute whole blocks of SQL statements. The easiest way to work with this tool is to create a wrapper script. For example, on Windows, you can create the following ij.bat file in your Windows directory (so it would automatically be on the path):

    @echo off     rem -- Run Derby ij tool--     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, you can call ij against an SQL script containing a collection of SQL statements for creating multiple tables, or inserting data in your database.

Forgot the password for the sample database? For Derby, try to use app and app for username and password. For Pointbase database, you might have a better chance with pbpublic and pbpublic.




NetBeans IDE Field Guide(c) Developing Desktop, Web, Enterprise, and Mobile Applications
NetBeans IDE Field Guide(c) Developing Desktop, Web, Enterprise, and Mobile Applications
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 279

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net