HSQLDB
URLS pour ouvrir une base HSQLBD avec JDBC
Dans tous les cas :
- la base s'appellera
base_commune
. - le pilote sera
org.hsqldb.jdbcDriver
Base en mémoire
jdbc:hsqldb:mem:base_commune
Connexion directe à la base sans utiliser le protocole TCP/IP
Connexion dite "StandAlone Engine" : on se connecte directement à la base de données grâce au système de fichiers Linux.
Une seule connexion possible à la fois.
jdbc:hsqldb:file:/home/eleve/basesHsqlDB/base_commune/base_commune;shutdown=true;create=true
Connexion au serveur à travers TCP/IP
jdbc:hsqldb:hsql://localhost:9001/basesHsqlDB/base_commune/base_commune,user=sa
Démarrer le serveur hsqldb en ligne de commandes
java -cp ~/prgrmms/java/hsqldb/lib/hsqldb.jar org.hsqldb.Server -database.0 file:basesHsqlDB/base1/base1 -dbname.0 base1 [Server@132e575]: Startup sequence initiated from main() method [Server@132e575]: Could not load properties from file [Server@132e575]: Using cli/default properties only [Server@132e575]: Initiating startup sequence... [Server@132e575]: Server socket opened successfully in 3 ms. [Server@132e575]: Database [index=0, id=0, db=file:basesHsqlDB/base1/base1, alias=base1] opened successfully in 327 ms. [Server@132e575]: Startup sequence completed in 331 ms. [Server@132e575]: 2017-12-12 11:44:23.777 HSQLDB server 2.4.0 is online on port 9001 [Server@132e575]: To close normally, connect and execute SHUTDOWN SQL [Server@132e575]: From command line, use [Ctrl]+[C] to abort abruptly
La première ligne démarrer le programme (classe avec méthode main()
) org.hsqldb.Server
qui se trouve dans l'archive
hsqldb.jar
.
Le terme base1
en fin de la première ligne est l'alias
de la base.
Démarrer la connexion cliente au serveur hsqldb grâce à l'outil sqltools
Se connecter à l'alias :
java -jar ~/prgrmms/java/hsqldb/lib/sqltool.jar --inlineRc=url=jdbc:hsqldb:hsql://localhost:9001/basesHsqlDB/base1,user=sa Enter password for sa: SqlTool v. 5736. JDBC Connection established to a HSQL Database Engine v. 2.4.0 database as "SA" with R/W TRANSACTION_READ_COMMITTED Isolation. SqlFile processor v. 5736. Distribution is permitted under the terms of the HSQLDB license. (c) 2004-2011 Blaine Simpson and the HSQL Development Group. \q to Quit. \? lists Special Commands. :? lists Edit-Buffer/History commands. *? lists PL commands. /? displays help on how to set and use macros (incl. functions). SPECIAL Commands begin with '\' and execute when you hit ENTER. EDIT-BUFFER / HISTORY Commands begin with ':' and execute when you hit ENTER. PROCEDURAL LANGUAGE commands begin with '*' and end when you hit ENTER. MACRO executions and definitions begin with '/' and end when you hit ENTER. All other lines comprise SQL Statements (or comments). SQL Statements are terminated by either unquoted ';' (which executes the statement), or a blank line (which moves the statement into the edit buffer without executing). After turning on variable expansion with command "*" (or any other PL command), PL variables may be used in most commands like so: *{PLVARNAME}. Be aware when using regular expressions on commands, that the regex.s operate only on the command text after the * or \ prefix, if any.
Exécution d'une requête SQL dans sqltools
sql> select * from categorie; CODE LIBELLE ----- --------------- FNTSY Fantasy RMN Roman RP Roman Policier SF Science-Fiction Fetched 4 rows. sql>\q eleve@mx1java:~ $
L'URL indiquée en première ligne
jdbc:hsqldb:hsql://localhost:9001/basesHsqlDB/base1/base1,user=sa
est celle qui sera écrite, dans votre programme Java, pour votre connexion jdbc
de la classe Bdd
.