Saturday, February 21, 2015

DERBY

Set Environment Variable
Path=C:\Program Files\Java\jdk1.7.0_04\db\bin;
DERBY_HOME= C:\Program Files\Java\jdk1.7.0_67\db
CLASSPATH=%DERBY_HOME%\lib\derby.jar;%DERBY_HOME%\lib\derbytools.jar;.
--------------------------------
VERIFY DERBY
 --------------------------------
sysinfo.bat
--------------------------------
START NETWORK SERVER
--------------------------------
startNetworkServer.bat
--------------------------------
START Command Line Client
--------------------------------
ij
java  org.apache.derby.tools.ij -p ij.properties
--------------------------------
NOTE: EVERY COMMAND END WITH SEMICOLON (;)
--------------------------------
HELP in ij
--------------------------------
ij>help;
ij>SHOW CONNECTIONS;
ij>SHOW TABLES;
ij>SHOW TABLES IN APP;
ij>DESCRIBE APP.CUSTOMERS;
ij>DISCONNECT;
ij>EXIT;
ij>DROP TABLE [TableName]
ij>SET SCHEMA APP
--------------------------------
CREATE & CONNECT NETWORK DATABASE
--------------------------------
ij>connect 'jdbc:derby://localhost:1527/MyDB;create=true;user=APP;password=APP';
ij>connect 'jdbc:derby://localhost:1527/MyDB;user=APP;password=APP';
ij>connect 'jdbc:derby:MyDB;user=APP;password=APP';
--------------------------------
ij command line tool with default settings from file (ij.properties)
--------------------------------
ij.user=APP
ij.database=MyDB;create=true;
ij.protocol=jdbc:derby:
derby.connection.requireAuthentication=true
derby.user.APP=APP
--------------------------------
Loading properties file
--------------------------------
ij>ij -p ij.properties
java org.apache.derby.tools.ij -p ij.properties

java -cp "target/dependency/*"  org.apache.derby.tools.ij -p ij.properties
--------------------------------
CREATE and LOAD database from SQL  File
--------------------------------
ij>run 'create_classicmodels.sql';
ij>run 'load_classicmodels.sql';
java org.apache.derby.tools.ij my_file.sql

--------------------------------
Derby Maven
--------------------------------
mvn dependency:copy-dependencies
--------------------------------
Derby in POM
--------------------------------
 <?xml version="1.0" encoding="UTF-8"? >
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
     <modelVersion >4.0.0 </modelVersion >
     <groupId >com.mastertheboss </groupId >
     <artifactId >EclipseJPAExample </artifactId >
     <version >1.0-SNAPSHOT </version >
     <repositories >
         <repository >
             <id >EclipseLink Repo </id >
             <url >http://download.eclipse.org/rt/eclipselink/maven.repo </url >
             <name >EclipseLink Repo </name >
         </repository >
     </repositories >
     <dependencies >
         <dependency >
             <groupId >org.apache.derby </groupId >
             <artifactId >derby </artifactId >
             <version >10.8.2.2 </version >
         </dependency >
         <dependency >
             <groupId >org.apache.derby </groupId >
             <artifactId >derbytools </artifactId >
             <version >10.8.2.2 </version >
         </dependency >
         <dependency >
             <groupId >org.eclipse.persistence </groupId >
             <artifactId >eclipselink </artifactId >
             <version >2.2.1 </version >
         </dependency >
         <dependency >
             <groupId >org.eclipse.persistence </groupId >
             <artifactId >javax.persistence </artifactId >
             <version >2.0.3 </version >
         </dependency > 
     </dependencies >
 </project >
--------------------------------
Help URL
--------------------------------
http://zetcode.com/db/apachederbytutorial/
--------------------------------
Sample
--------------------------------
ij>connect 'jdbc:derby://localhost:1527/myDB;user=me;password=mine';
ij>create table foo (id integer, name varchar(20));
ij>insert into foo values (1, 'derby');
ij>insert into foo values (2, 'derby plug-ins');
ij>disconnect;
ij>exit;
Derby Embedded Server
ij>connect 'jdbc:derby:myDB;create=true;user=me;password=mine';

No comments:

Post a Comment