0

I'm trying to connect to my hsqlDb via java script but what ever i add in the db it can't be saved and it doesnt generate any error ! the same when i try to get data from the db and i use Result.next() it generete nulPointerExeption even i have data in my table

 Connection con = null; 
    try {
        Class.forName("org.hsqldb.jdbcDriver");
         con = DriverManager.getConnection("jdbc:hsqldb:file:GestionPiecesDB\\GestionPiece;hsqldb.lock_file=false", "root", "");

    } catch (SQLException e) {
        System.out.println(e);
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(DataBaseTest.class.getName()).log(Level.SEVERE, null, ex);
    }
    System.out.print("connected \n");
    Statement stmn;
    try {
        stmn = con.createStatement();
        stmn.executeUpdate("insert into users (nom ,nature , mot_passe ) values ('admin' ,'admin' , 'admin')");
    } catch (SQLException ex) {
    }
    System.out.print("created \n");

    Statement sn;
    ResultSet r ;
    try {
        sn = con.createStatement();
        r = sn.executeQuery("select * from users");
        if(r.next())
             System.out.print("value \n");
        else
            System.out.print("not value \n");               
    } catch (SQLException ex) {
    }
Nicktar
  • 5,548
  • 1
  • 28
  • 43

1 Answers1

0

You are catching the exceptions and continuing the program. This means you will not see any errors. Add throws SQLException to the method signature and remove all the try {} catch blocks for this exception.

Your file path should be absolute. For example:

DriverManager.getConnection("jdbc:hsqldb:file:C:\\GestionPiecesDB\\GestionPiece", "root", "")

And you should not disable the lock file for normal use.

fredt
  • 24,044
  • 3
  • 40
  • 61
  • even so it's not working ! can it be because i'm using hsql manger to create the database !!? because when i connect fro a server every thing works fine – Fatiha IMOUSSAINE Feb 29 '20 at 20:41
  • It should work with absolute file path. But `jdbc:hsqldb:file:` connections can be made from only one program at a time. The server mode is better because you can connect from more than one program. – fredt Mar 02 '20 at 12:27