How to use Derby database

Well, I directly jump into the subject matter instead of taking you through its history and detail; because you may be already aware or if not you can google it.

Please follow these following steps:-

1. Download the Apache Derby binary distribution (e.g., v10.6) from the Apache Derby web site ( http://db.apache.org/derby/
) and extract it to a directory of your choice to complete the installation. Say for instance you have extracted it into 'c:\derby' folder.
2. Set ‘DERBY_INSTALL’ as user environment variable in you computer first.
3. Go to the physical location of ‘DERBY_INSTALL’ .and start the bat file ‘C:\derby\bin\startNetworkServer.bat’ by double clicking it . This will start the database server. Minimize this started command prompt.
4. Now, open a new command prompt
5. set CLASSPATH=%DERBY_INSTALL%\lib\derby.jar;%DERBY_INSTALL%\lib\derbytools.jar;%CLASSPATH%
6. To run the sysinfo utility, type the following in a command window or shell: java org.apache.derby.tools.sysinfo
7. Then type in command line ij;
8. ij> will appear, there you type connect 'jdbc:derby:/DerbyDB/vehicle;create=true';
9. This creates a new folder like DerbyDB in c: -> the directory tree C:\DerbyDB\vehicle
10. To create the tables, create a txt file (C:\DerbyDB\vehicle\create_sql.txt) which will contain all the sql commands in it to create tables.
11. Then run this command:-> run 'C:/DerbyDB/vehicle/create_sql.txt';
12. This will create a new tables. NOTE:- Remember this file was containig only create command for table.
13. To insert data in those tables create a separate txt file and run them as per the previous command.
14. To quit ij simple enter: exit;

Note: Remember instead of writing query in a txt file and executing it, can be avoided by directly typing the SQL command in console itself. But remember each command must end with a semicolon.



Using Derby in Eclipse IDE

Please follow these steps :

1
To install the Derby plugins manually, you will need to download the Apache Derby Eclipse Plugins from this website: http://db.apache.org/derby/derby_downloads.html.

2
The plugins are named 'derby_core_plugin_xx.zip' and 'derby_ui_plugin_xx.zip'.
Download both of these ZIP and unzip them. From these unziped folders copy these three folders and paste them into 'c:\eclipse\plugin' folder:

org.apache.derby.core_10.4.2,
org.apache.derby.ui_1.1.2, and
org.apache.derby.plugin.doc_1.1.2.


3
Re-start the eclipse
Select the project -> right click-> Apache derby-> Add Apache derby Nature.
Select the project -> right click-> Apache derby-> Start derby Network server

You will get the console output in eclipse:
Apache Derby Network Server - 10.5.3.0 - (802917) started and ready to accept connections on port 1527


4
Select the project -> right click-> Apache derby-> ij (ij Interactive SQL)
In Eclipse console type:
connect 'jdbc:derby:/DerbyDB/testDB;create=true';

This will create a database named 'testDB' inside the eclipse folder. ie, if eclipse is inside c:\eclipse, then you will find a new folder named 'testDB' is created as -> c:\eclipse\testDB

5
To creat a table in testDB:in Elipse console type:
CREATE TABLE BOOK_TABLE (BOOK_ISBN VARCHAR(50) );

it will give the output:-> 0 rows inserted/updated/deleted
this means it will create a table.



Thus, you will get the Database and Tables created in Derby database.

Comments

Popular posts from this blog

Java

RTC - Repository : How to Revert Back the Changes