Read Catalogue
- 1. Derby Introduction
- 2. Slightly Configure the environment variable
- 3. Derby Operations and Java access
Back to top of 1. About Derby
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.
Back to top of 2. environment variable under a slight configuration
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 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
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 of 3. Derby Operations and Java access
A. Create a database and connect (there is a connection, there is no post-creation connection)
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: 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
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 (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 void Main (string[] args) {derbytest derbytest = new Derbytest (); Loaddriver (); Derbytest.getdatafromderby (); }}
Http://www.cnblogs.com/java-class/p/5753997.html
Compact Database Derby Usage Tips