Compact database Apache Derby usage tips

Source: Internet
Author: User
Tags compact

1. Derby Introduction

The reason to focus on little Derby is that pure green, light, memory footprint, minutes in your machine run up, do some of your own code to connect the database to practice very convenient.

Although Mysql can also, more than a choice, not also very good?

Apache Derby is a database written entirely in Java, and Derby is a product of open source.

Apache Derby is very small and the core part of Derby.jar is only 2 m, which can be used as a separate database server or embedded in the application.

Official website:

Click to enter the version, note the requirements of the build environment, click Download Zip extract to the random directory.

650) this.width=650; "Src=" Http:// " Style= "margin:0px;padding:0px;border:0px;"/>

Back to Top

2. Slightly Configure the environment variable

Derby is written in Java and you need a Java JRE on your machine, not to mention installation and configuration.

Here is the system environment variable that Derby needs to configure, and the configuration environment variable is to let the system know where to find the execution program for the command.

Name:derby_home value:e:\java\derby\db-derby- in Path join:%derby_home%\bin in classpath join:%derby_home%\lib \derby.jar;%d erby_home%\lib\derbyclient.jar;%d erby_home%\lib\derbytools.jar;%d Erby_home%\lib\derbynet.jar

Cut to the cmd black box and knock SysInfo

650) this.width=650; "Src=" PNG "style=" margin:0px;padding:0px;border:0px; "/>

At this point, the small Derby has been successfully installed on your computer, is not fast? Sao years, can be carried on toss.

Back to Top

3. Derby Operations and Java access

A. Create a database and connect (there is a connection, there is no post-creation connection)

Connect ' jdbc:derby:dedb;user=root;password=root;create=true ';

B. Creating a new system User table

CREATE TABLE T_user (UUID varchar), name varchar (ten), age int, address varchar (40));

C. Inserting some test data

INSERT into T_user values (' b82a6c5244244b9bb226ef31d5cbe508 ', ' Miachel ', ' Street 1 ') and insert into t_user values (' b82a6c5244244b9bb226ef31d5cbe509 ', ' Andrew ', and ' street 1 '); INSERT into t_user values (' b82a6c5244244b9bb226ef31d5cbe510 ', ' Orson ', +, ' street 1 '); INSERT into t_user values (' b82a6c5244244b9bb226ef31d5cbe511 ', ' Rambo ', +, ' street 1 ');

Note: Operation Derby requires the use of the IJ tool (similar to Oracle Plus), and the CMD input IJ will enter IJ mode;

The path to creating the database depends on the path of your CMD, such as the Derby database created under C:\users\administrator>, under that directory;

If you're familiar with SQL, there's nothing wrong with doing derby.

E. Using Derby in Java programs

650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" Margin:0px;padding:0px;border:none; "/>

import java.sql.*;p ublic class derbytest {    private static  String driver =  "Org.apache.derby.jdbc.EmbeddedDriver";     private  static String protocol =  "Jdbc:derby:";     string dbname  =  "E:\\users\\workspaces\\derby\\dedb";    public static void  Loaddriver ()  {        try {             class.forname (Driver). newinstance ();         } catch  (exception e)  {             e.printstacktrace ();        }     }    public void getdatafromderby ()  {         try {            connection conn =  Drivermanager.getconnection (protocol + dbname +  "; User=root;password=root;create=true");             Statement statement =  Conn.createstatement ();            resultset  Resultset = statement.executequery ("Select * from t_user");             while  ( ())  {                 system.out.println (resultSet.getString (1));                  System.out.println (resultset.getstring (2));             }    &nbSp;       conn.close ();             statement.close ();             resultset.close ();        } catch  (EXCEPTION E1)  {            e1.printstacktrace ();         }    }    public static  void main (String[] args)  {        DerbyTest  Derbytest = new derbytest ();         loaddriver ();         derbytest.getdatafromderby ();     }}

650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" Margin:0px;padding:0px;border:none; "/>

Compact database Apache Derby usage tips

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.