Compact Database 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: http://db.apache.org/derby/derby_downloads.html

Click to enter the version, pay attention to the requirements of build environment, click Download Zip unzip the random directory.

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-10.10.1.1-bin in path join:%derby_home%\ Bin    Join in Classpath:%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

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

3. Derby Operations and Java access

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

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

B. Creating a new system User table

Create Table varchar (varchar(+);

C. Inserting some test data

Insert  intoT_userValues('b82a6c5244244b9bb226ef31d5cbe508','Miachel', -,'Street 1');Insert  intoT_userValues('b82a6c5244244b9bb226ef31d5cbe509','Andrew', *,'Street 1');Insert  intoT_userValues('b82a6c5244244b9bb226ef31d5cbe510','Orson', -,'Street 1');Insert  intoT_userValues('b82a6c5244244b9bb226ef31d5cbe511','Rambo', +,'Street 1');

Note: The path to creating the database depends on the path of your CMD. If you're familiar with SQL, there's nothing wrong with doing derby.

E. Using Derby in Java programs

ImportJava.sql.*; Public classDerbytest {Private StaticString Driver = "Org.apache.derby.jdbc.EmbeddedDriver"; Private StaticString protocol = "Jdbc:derby:"; String DbName= "E:\\users\\workspaces\\derby\\dedb";  Public Static voidLoaddriver () {Try{class.forname (driver). newinstance (); } Catch(Exception e) {e.printstacktrace (); }    }     Public voidGetdatafromderby () {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(Resultset.next ()) {System.out.println (resultset.getstring (1)); System.out.println (Resultset.getstring (2));            } conn.close ();            Statement.close ();        Resultset.close (); } Catch(Exception E1) {e1.printstacktrace (); }    }     Public Static voidMain (string[] args) {derbytest derbytest=Newderbytest ();        Loaddriver ();    Derbytest.getdatafromderby (); }}

Compact Database 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: 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.