use derby ij against an existing database

While I'm having some trouble installing and setting up derby, I do have partial success:

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# 

How do I now query this particular database?

preguntado el 24 de agosto de 12 a las 00:08

2 Respuestas

A full example, using Derby and Squirrel, presuming you have a Derby database already installed on the system:

  1. Instale SQL ardilla dentro $HOME/bin/squirrel
  2. Instale Derby de Apache dentro $HOME/bin/db-derby
  3. Run Squirrel (cd $HOME/bin/squirrel ; ./squirrel-sql.sh)
  4. Presione Drivers to open the Drivers panel.
  5. Haga doble clic en Apache Derby Embedded.
  6. Presione Extra Class Path.
  7. Presione Añada.
  8. Elija una $DERBY_HOME/lib/derby.jar.
  9. Kit URL de ejemplo to the database path (e.g., the directory containing seg0).
  10. Presione OK para guardar.

At this point the Apache Derby Embedded icon should no longer have a red X.

Entonces:

  1. Haga clic en el Alias .
  2. Kit Nombre to: DerbyDB
  3. Asegurar Destornillador is set to: Apache Derby Embedded
  4. Verificar el Enlance is pointing to the directory containing seg0.
  5. Presione OK (no username or password needed?).
  6. Presione Conéctate.

The database is now connected and you should see the schemas.

Entonces:

  1. Prensa Ctrl + n to display a new SQL editor window, or click the SQL .
  2. Tipo: SELECT * FROM SYS.SYSTABLES
  3. Click the Running human icon (or press Ctrl + Shift + Enter) to execute the query.

You can now execute SQL statements against the Derby database.

Note: This does not technically answer the question, as this answer does not explain how to use the interactive command-line interface (ij). The answer proposes a viable alternative to querying the database using Squirrel's graphical interface.

Respondido 29 Jul 13, 18:07

I still don't know how to really query the db itself, but it's fairly simple to connect, aparentemente:

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# 

contestado el 23 de mayo de 17 a las 13:05

an example query would be: select * from app.james_mailbox; - bryan pendleton

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.