Install, configure, and use the Derby Database

Source: Internet
Author: User
Derby database is a pure memory database implemented in Java and is an open-source project of Apache. Because it is implemented in Java, it can be run on any platform.

Derby database is a pure memory database implemented in Java and is an open-source project of Apache. Because it is implemented in Java, it can be run on any platform.

Derby database is a pure memory database implemented in Java and is an open-source project of Apache. Because it is implemented in Java, it can be run on any platform. Another feature is that it is small in size and free of installation. You only need a few small jar packages to run it. The following describes the installation and configuration.

Install

12.16.download the derbydata Library (such as db-derby-10.10.1.1-bin.zip) from apacheand decompress it to any directory (such as D: \ Derby \ db-derby-10.10.1.1-bin ).
2). Configure the environment variable DERBY_HOME = D: \ Derby \ db-derby-10.10.1.1-bin
And add it to the path and classpath environment variables (% DERBY_HOME % \ bin; % DERBY_HOME % \ lib \ derbyrun. jar)
3) Test Database Installation C: \> sysinfo
------------------ Java Information ------------------
Java Version: 1.7.0 _ 40
Java Vendor: Oracle Corporation
Java home: C: \ Program Files \ Java \ jdk1.7.0 _ 40 \ jre
Java classpath: D: \ Derby \ db-derby-10.10.1.1-bin \ bin; D: \ Derby \ db-derby-10.10.1.1-bin \ lib \ derbyrun. jar;
OS name: Windows 7
OS architecture: amd64
OS version: 6.1
Java user name: qqqqq
Java user home: D: \ userdata \ qqq
Java user dir: C :\
Java. specification. name: Java Platform API Specification
Java. specification. version: 1.7
Java. runtime. version: 1.7.0 _ 40-b43
--------- Derby Information --------
[D: \ Derby \ db-derby-10.10.1.1-bin \ lib \ derby. jar] 10.10.1.1-(1458268)
[D: \ Derby \ db-derby-10.10.1.1-bin \ lib \ derbytools. jar] 10.10.1.1-(1458268)
[D: \ Derby \ db-derby-10.10.1.1-bin \ lib \ derbynet. jar] 10.10.1.1-(1458268)
[D: \ Derby \ db-derby-10.10.1.1-bin \ lib \ derbyclient. jar] 10.10.1.1-(1458268)

Connection

C: \> ij
Ij 10.10
Ij> CONNECT 'jdbc: derby: D: \ Project \ derbyDB \ testdb; create = true'; (if the database testdb does not exist, create and modify the database)
Ij> CONNECT 'jdbc: derby: D: \ Project \ derbyDB \ testdb; '; (CONNECT to the testdb database)
Ij (CONNECTION1)> create table firsttable (id int primary key, name varchar (12); (create table)
0 rows inserted/updated/deleted
Ij (CONNECTION1)> insert into firsttable values (10, 'ten '), (20, 'twenty'), (30, 'Thirty'); (INSERT data)
3 rows inserted/updated/deleted
Ij (CONNECTION1)> SELECT * from firsttable;
ID | NAME
------------------------
10 | TEN
20 | TWENTY
30 | THIRTY
3 rows selected
Ij (CONNECTION1)> exit; (exit)

Description

1. The sysinfo tool is used to display Java environment information and Derby version information.

2. the ij tool performs database interaction and executes SQL scripts, such as query, addition, deletion, modification, and table creation.

Example

The following is a complete example of how to operate JavaDB in a program.

Import java. SQL. Connection;
Import java. SQL. DriverManager;
Import java. SQL. ResultSet;
Import java. SQL. Statement;
Import java. util. Properties;

Public class TestDerby {
Public static void main (String [] args ){
Try {
Class. forName ("org. apache. derby. jdbc. EmbeddedDriver"). newInstance ();
System. out. println ("Load the embedded driver ");
Connection conn = null;
Properties props = new Properties ();
Props. put ("user", "user1"); props. put ("password", "user1 ");
Conn = DriverManager. getConnection ("jdbc: derby: C: \ Project \ derbyDB \ testdb ;");
System. out. println ("create and connect to testdb ");

Statement s = conn. createStatement ();
ResultSet rs = s.exe cuteQuery ("SELECT * from firsttable ");
System. out. println ("name \ t \ tscore ");
While (rs. next ()){
StringBuilder builder = new StringBuilder (rs. getString (1 ));
Builder. append ("\ t ");
Builder. append (rs. getInt (1 ));
System. out. println (builder. toString ());
}

} Catch (InstantiationException e ){
E. printStackTrace ();
} Catch (IllegalAccessException e ){
E. printStackTrace ();
} Catch (ClassNotFoundException e ){
E. printStackTrace ();
} Catch (Exception e ){
E. printStackTrace ();
}

}

}

Detailed descriptions of Hadoop cluster, hive, and Derby installation and deployment

Experience Java-only database-Derby

[Recommended] expert bargaining skills for optimizing Derby Databases

Configure Hive to use the embedded Derby or customer service mode Derby Method

ERROR 42Y07 when using the Derby database for the first connection

Derby details: click here
Derby: click here

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: info-contact@alibabacloud.com 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.