Verouillage dans HSQL

Verouillage dans HSQL - SQL/NoSQL - Programmation

Marsh Posté le 08-05-2010 à 11:36:43    

Bonjour tous le monde,
je cherche depuis plusieurs jours comment verrouillé une table dans HSQL .
c'est pas la même syntaxe que SQL .
j'ai utilisé la syntaxe :

Code :
  1. LOCK Table MaTable Read

mais sa ne marche pas.
 
voici mon code :

Code :
  1. public static void main(String[] args) throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException, SAXException, IOException, ParserConfigurationException
  2. {
  3.  ResultSet resultat = connexion("SELECT nom FROM Banque WHERE num_compte = 1987 " );
  4.  if(resultat.next())
  5.  {
  6.   String nom=resultat.getString("nom" );
  7.   System.out.println(nom);
  8.  }
  9.  resultat=connexion("LOCK TABLE Banque Read" );
  10.  resultat = connexion("SELECT nom FROM Banque WHERE num_compte = 1987 " );
  11.  if(resultat.next())
  12.  {
  13.   String nom=resultat.getString("nom" );
  14.   System.out.println(nom);
  15.  }
  16.  else
  17.   System.out.println("Lock" );
  18. }
  19. //======================================================
  20. public static ResultSet connexion( String requete)
  21. {
  22.  ResultSet resultat=null;
  23.  try
  24.  {
  25.   System.out.println(requete);
  26.   Class.forName("org.hsqldb.jdbcDriver" ).newInstance();
  27.   Connection connexion = DriverManager.getConnection("jdbc:hsqldb:file:C:\\mydatabases\\BDD_Banque", "sa", "" );
  28.   Statement st = connexion.createStatement();
  29.   resultat = st.executeQuery(requete);
  30.   //Sauvegarde et fermeture de la connexion:
  31.   st.executeQuery("SHUTDOWN" );
  32.   st.close();
  33.   connexion.close() ;
  34.  }catch (Exception ex1) {
  35.   System.out.println("Exeption >>>>> connexion()" );
  36.             ex1.printStackTrace();
  37.  }
  38.  return resultat;
  39. }


 
 
voila ce qui est écrie dans la FAQ HSQL
 
 
LOCK TABLE
 
lock table statement
 
<lock table statement> ::= LOCK TABLE <table name> { READ | WRITE} [, <table name> { READ | WRITE} ...]}
 
In some circumstances, where multiple simultaneous transactions are in progress, it may be necessary to ensure a transaction consisting of several statements is completed, without being terminated due to possible deadlock. When this statement is executed, it waits until it can obtain all the listed locks, then returns. The SQL statements following this statements use the locks already obtained (and obtain new locks if necessary) and can proceed without waiting. All the locks are released when a COMMIT or ROLLBACK statement is issued. Currently, this command does not have any effect when the database transaction control model is MVCC.

Example 3.3. Locking Tables

 
    LOCK TABLE table_a WRITE, table_b READ
 
 
merci pour votre aide c'est très urgent.


Message édité par man_u le 08-05-2010 à 12:30:26
Reply

Marsh Posté le 08-05-2010 à 11:36:43   

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed