vendredi 29 janvier 2016

foreach data in database

I have been working on writing a code which is going to encrypt the data in a database using java, I want to get every and each data in the database, encrypt it, insert to another copy of the database or even update the same database, but I do not know how to do it, and the following code won't help me. the database is sqlite.

try {
        AESCipher coder=new AESCipher();
        Class.forName("org.sqlite.JDBC");
        c = DriverManager.getConnection("jdbc:sqlite:E:\\AndroidProjects\\Psychology\\app\\src\\main\\assets\\database");
        c.setAutoCommit(false);
        stmt = c.createStatement();
        for(int m=1; m<= getTableCount();m++) {
            ResultSet rs = stmt.executeQuery("SELECT * FROM Exam"+m);
            ResultSetMetaData rsmd = rs.getMetaData();
            int columnsNumber = rsmd.getColumnCount();
            while (rs.next()) {
                for (int i = 1; i <= columnsNumber; i++) {
                    rs.updateString(i,coder.encrypt(rs.getString(i),10000, AESCipher.KeyLength.ONE_TWENTY_EIGHT));
                }
            }
            rs.close();
            stmt.close();
            c.close();
        }
    } catch ( Exception e ) {
        System.err.println( e.getClass().getName() + ": " + e.getMessage() );
        System.exit(0);
    }

Aucun commentaire:

Enregistrer un commentaire