Installation and use of Derby database

Source: Internet
Author: User

Derby database is a pure use Java the implemented memory database. an open source project belonging to Apache. Because it is implemented in Java , it can be executed on whatever platform. Another feature is the small size, no installation, just need a few small jar package can be executed.

The following is the installation and configuration

Installation

1). Download the Derby database (such as Db-derby-10.10.1.1-bin.zip) from Apache and unzip it to a random folder (e.g., 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 to the path and CLASSPATH environment variables (%derby_home%\bin;%d Erby_home%\lib\derbyrun.jar) 3). Test Database Installation C:\>sysinfo------------------Java information------------------Java Ver sion:1.7.0_40 java vendor:oracle Corporation java home:c:\program files\java\jdk1.7.0_40\jre Java class Path: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:\user DATA\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 Version number 10.10  ij> CONNECT ' jdbc:derby:d:\project\derbydb\testdb;create=true '; (assuming the database testdb does not exist, The database is created)  ij> CONNECT ' jdbc:derby:d:\project\derbydb\testdb; ';           (Connect testdb database)  ij (CONNECTION1) > CREATE TABLE firsttable (ID INT PRIMARY key,name VARCHAR (12)); (create table)  inserted/updated/ Delete 0 rows of  ij (CONNECTION1) > INSERT INTO Firsttable VALUES (ten, ' TEN '), (+, ' twenty '), (+, ' thirty '); (insert data)  inserted/updated /delete 3 rows of  ij (CONNECTION1) > SELECT * from firsttable;  ID |name  ------------------------  10 | TEN  20 | Twenty  30 | Thirty  has selected 3 rows  
Description

1. The SysInfo tool is used to display Java Environment information and Derby version number information.


2. ij tool for database interaction, run SQL scripts such as queries, deletions, create tables, etc.


Sample Example

The following is a complete example. 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 ();p rops.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.executequery ("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 ();}}}



Installation and use of Derby database

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.