前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Javadb学习 连接Javadb的两种方法 javadb-10_5_1_1.zip[通俗易懂]

Javadb学习 连接Javadb的两种方法 javadb-10_5_1_1.zip[通俗易懂]

作者头像
全栈程序员站长
发布2022-09-08 09:46:25
9860
发布2022-09-08 09:46:25
举报
文章被收录于专栏:全栈程序员必看

大家好,又见面了,我是你们的朋友全栈君。

Javadb学习

环境变量设置:

DERBY_HOME=D:\ProgramFiles\Environment\javadb

path=.;%JAVA_HOME%/bin;%path%;%CATALINA_HOME%/bin;%ANT_HOME%/bin;%ANT_HOME%/bin;C:\Program Files\IDM Computer Solutions\UltraEdit\;%JAVA_HOME%\jre\lib;%DERBY_HOME%\bin

classpath=.;%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\bin;%JAVA_HOME%\jre\lib;%DERBY_HOME%\lib\derby.jar;%DERBY_HOME%\lib\derbyclient.jar;%DERBY_HOME%\lib\derbynet.jar;%DERBY_HOME%\lib\derbyrun.jar

开启Javadb服务:

java -jar %derby_home%\lib\derbyrun.jar server start

关闭javadb服务

java -jar %derby_home%\lib\derbyrun.jar server shutdown

ij

ij> exit; 退出

Email server : derby-user@db.apache.org

用ij连接数据库javadb

Creating a Derby database and running SQL statements Now, you will use the Derby ij tool to load the Derby database engine. You will use the Derby embedded driver to create and connect to the firstdb database. You will also use a few basic SQL statements to create and populate a table. 1. Run the Derby ij tool. If you included the DERBY_HOME/bin directory in your PATH environment variable, type: ij Otherwise, you can use the java command to start the ij tool. Operating System Command UNIX (Korn Shell) java -jar $DERBY_HOME/lib/derbyrun.jar ij ij version 10.5 Windows java -jar %DERBY_HOME%\lib\derbyrun.jar ij ij version 10.5 2. Create the database and open a connection to the database using the embedded driver. CONNECT ‘jdbc:derby:firstdb;create=true’; Description of connection command: connect The ij command to establish a connection to a database. The Derby connection URL is enclosed in single quotation marks. An ij command can be in either uppercase or lowercase. jdbc:derby: The JDBC protocol specification for the Derby driver. firstdb The name of the database. The name can be any string. Because no filepath is specified, the database is created in the default working directory (DERBYTUTOR). ;create=true The Derby URL attribute that is used to create a database. Derby does not have an SQL create database command. ; Getting Started with Java DB 23 The semicolon is the ij command terminator. 3. Create a table with two columns using standard SQL. CREATE TABLE FIRSTTABLE (ID INT PRIMARY KEY, NAME VARCHAR(12)); 0 rows inserted/updated/deleted 4. Insert three records. INSERT INTO FIRSTTABLE VALUES (10,’TEN’),(20,’TWENTY’),(30,’THIRTY’); 3 rows inserted/updated/deleted 5. Perform a simple select of all records in the table. SELECT * FROM FIRSTTABLE; ID |NAME ———————— 10 |TEN 20 |TWENTY 30 |THIRTY 3 rows selected 6. Perform a qualified select of the record with column ID=20. SELECT * FROM FIRSTTABLE WHERE ID=20; ID |NAME ———————— 20 |TWENTY 1 row selected 7. Optional: Create and populate additional tables and other schema objects. a. Load the SQL script ToursDB_schema.sql. run ‘ToursDB_schema.sql’; ij> … CREATE TABLE AIRLINES ( AIRLINE CHAR(2) NOT NULL , AIRLINE_FULL VARCHAR(24), BASIC_RATE DOUBLE PRECISION, … 0 rows inserted/updated/deleted … Other output messages not shown … b. Populate the tables with data by running the script loadTables.sql. run ‘loadTables.sql’; ij> run ‘loadCOUNTRIES.sql’; ij> insert into COUNTRIES values ( ‘Afghanistan’,’AF’,’Asia’); 1 row inserted/updated/deleted ij> insert into COUNTRIES values ( ‘Albania’,’AL’,’Europe’); 1 row inserted/updated/deleted … Other output messages not shown … 8. Exit the ij tool. exit; You should be returned to the DERBYTUTOR directory. 9. Browse the most

Activity 2: Run SQL using the client driver

java -jar %DERBY_HOME%\lib\derbyrun.jar server start

换一个dos窗口

java -jar %DERBY_HOME%\lib\derbyrun.jar ij

CONNECT ‘jdbc:derby://localhost:1527/seconddb;create=true’;

备注区别:CONNECT ‘jdbc:derby:firstdb;create=true’;

CREATE TABLE SECONDTABLE (ID INT PRIMARY KEY, NAME VARCHAR(14)); 0 rows inserted/updated/deleted

INSERT INTO SECONDTABLE VALUES (100,’ONE HUNDRED’),(200,’TWO HUNDRED’),(300,’THREE HUNDRED’); 3 rows inserted/updated/deleted

SELECT * FROM SECONDTABLE; ID |NAME ———————— 100 |ONE HUNDRED 200 |TWO HUNDRED 300 |THREE HUNDRED 3 rows selected

Exit ij.

java -jar %DERBY_HOME%\lib\derbyrun.jar server shutdown

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/156994.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
数据库
云数据库为企业提供了完善的关系型数据库、非关系型数据库、分析型数据库和数据库生态工具。您可以通过产品选择和组合搭建,轻松实现高可靠、高可用性、高性能等数据库需求。云数据库服务也可大幅减少您的运维工作量,更专注于业务发展,让企业一站式享受数据上云及分布式架构的技术红利!
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档