将derby ij用于现有数据库

时间:2012-08-23 23:54:23

标签: database ubuntu command-line-interface derby

虽然我有some trouble installing and setting up derby,但我确实取得了部分成功:

root@dur:~/apache-james-3.0-beta4/var/store/derby# 
root@dur:~/apache-james-3.0-beta4/var/store/derby# ll
total 36
drwxr-xr-x 5 root root  4096 Aug 23 16:46 ./
drwxr-xr-x 5  501 staff 4096 Aug 23 02:07 ../
-rw-r--r-- 1 root root     4 Aug 23 02:07 dbex.lck
-rw-r--r-- 1 root root    38 Aug 23 02:07 db.lck
-rw-r--r-- 1 root root   187 Aug 23 16:46 derby.log
drwxr-xr-x 2 root root  4096 Aug 23 02:07 log/
drwxr-xr-x 2 root root  4096 Aug 23 02:07 seg0/
-rw-r--r-- 1 root root   868 Aug 23 02:07 service.properties
drwxr-xr-x 2 root root  4096 Aug 23 02:07 tmp/
root@dur:~/apache-james-3.0-beta4/var/store/derby# 
root@dur:~/apache-james-3.0-beta4/var/store/derby# java org.apache.derby.tools.ij
ij version 10.9
ij> quit;
root@dur:~/apache-james-3.0-beta4/var/store/derby# 

我现在如何查询此特定数据库?

2 个答案:

答案 0 :(得分:2)

使用Derby和Squirrel的完整示例,假设您已在系统上安装了Derby数据库:

  1. Squirrel SQL安装到$HOME/bin/squirrel
  2. Apache Derby安装到$HOME/bin/db-derby
  3. 运行Squirrel(cd $HOME/bin/squirrel ; ./squirrel-sql.sh
  4. 点击驱动程序以打开“驱动程序”面板。
  5. 双击 Apache Derby Embedded
  6. 点击额外路径
  7. 点击添加
  8. 选择$DERBY_HOME/lib/derby.jar
  9. 示例网址设置为数据库路径(例如,包含seg0的目录)。
  10. 点击确定进行保存。
  11. 此时,Apache Derby Embedded图标不应再有红色X.

    然后:

    1. 点击别名标签。
    2. 名称设置为:DerbyDB
    3. 确保驱动程序设置为:Apache Derby Embedded
    4. 确认网址指向包含seg0
    5. 的目录
    6. 点击确定(不需要用户名或密码?)。
    7. 点击连接
    8. 数据库现已连接,您应该看到模式。

      然后:

      1. Ctrl + n 显示新的SQL编辑器窗口,或单击 SQL 选项卡。
      2. 输入:SELECT * FROM SYS.SYSTABLES
      3. 单击Running human图标(或按 Ctrl + Shift + Enter )执行查询。
      4. 您现在可以对Derby数据库执行SQL语句。

        注意:这在技术上没有回答这个问题,因为这个答案没有解释如何使用交互式命令行界面(ij)。答案提出了一种使用Squirrel图形界面查询数据库的可行替代方案。

答案 1 :(得分:1)

我仍然不知道如何真正查询数据库本身,但连接相当简单,apparently

root@dur:~/apache-james-3.0-beta4/var/store/derby# 
root@dur:~/apache-james-3.0-beta4/var/store/derby# pwd
/root/apache-james-3.0-beta4/var/store/derby
root@dur:~/apache-james-3.0-beta4/var/store/derby# 
root@dur:~/apache-james-3.0-beta4/var/store/derby# ll
total 24
drwxr-xr-x 4 root root  4096 Aug 23 18:24 ./
drwxr-xr-x 5  501 staff 4096 Aug 23 02:07 ../
-rw-r--r-- 1 root root  1092 Aug 23 18:24 derby.log
drwxr-xr-x 2 root root  4096 Aug 23 02:07 log/
drwxr-xr-x 2 root root  4096 Aug 23 02:07 seg0/
-rw-r--r-- 1 root root   868 Aug 23 02:07 service.properties
root@dur:~/apache-james-3.0-beta4/var/store/derby# 
root@dur:~/apache-james-3.0-beta4/var/store/derby# java org.apache.derby.tools.ij 
ij version 10.9
ij> connect 'jdbc:derby:/root/apache-james-3.0-beta4/var/store/derby';
ij> 
;
ij> show schema;
ERROR 42X01: Syntax error: Encountered "show" at line 1, column 1.
Issue the 'help' command for general information on IJ command syntax.
Any unrecognized commands are treated as potential SQL commands and executed directly.
Consult your DBMS server reference documentation for details of the SQL syntax supported by your server.
ij> 
;
ij> show schemas;
TABLE_SCHEM                   
------------------------------
APP                           
NULLID                        
SQLJ                          
SYS                           
SYSCAT                        
SYSCS_DIAG                    
SYSCS_UTIL                    
SYSFUN                        
SYSIBM                        
SYSPROC                       
SYSSTAT                       

11 rows selected
ij> show tables;
TABLE_SCHEM         |TABLE_NAME                    |REMARKS             
------------------------------------------------------------------------
SYS                 |SYSALIASES                    |                    
SYS                 |SYSCHECKS                     |                    
SYS                 |SYSCOLPERMS                   |                    
SYS                 |SYSCOLUMNS                    |                    
SYS                 |SYSCONGLOMERATES              |                    
SYS                 |SYSCONSTRAINTS                |                    
SYS                 |SYSDEPENDS                    |                    
SYS                 |SYSFILES                      |                    
SYS                 |SYSFOREIGNKEYS                |                    
SYS                 |SYSKEYS                       |                    
SYS                 |SYSPERMS                      |                    
SYS                 |SYSROLES                      |                    
SYS                 |SYSROUTINEPERMS               |                    
SYS                 |SYSSCHEMAS                    |                    
SYS                 |SYSSEQUENCES                  |                    
SYS                 |SYSSTATEMENTS                 |                    
SYS                 |SYSSTATISTICS                 |                    
SYS                 |SYSTABLEPERMS                 |                    
SYS                 |SYSTABLES                     |                    
SYS                 |SYSTRIGGERS                   |                    
SYS                 |SYSVIEWS                      |                    
SYSIBM              |SYSDUMMY1                     |                    
APP                 |JAMES_DOMAIN                  |                    
APP                 |JAMES_MAIL                    |                    
APP                 |JAMES_MAILBOX                 |                    
APP                 |JAMES_MAIL_PROPERTY           |                    
APP                 |JAMES_MAIL_USERFLAG           |                    
APP                 |JAMES_RECIPIENT_REWRITE       |                    
APP                 |JAMES_SUBSCRIPTION            |                    
APP                 |JAMES_USER                    |                    
APP                 |OPENJPA_SEQUENCE_TABLE        |                    

31 rows selected
ij> quit;
root@dur:~/apache-james-3.0-beta4/var/store/derby#