0

I would like to update the JTable without AES_ENCRYPT the data is can be updated and viewed, but since the data is encrypted each time i try to call this method the data is still encrypted. how can I use solve this issue ?

private void Update_Table(){



     try{
         String sql  = "SELECT ID, AES_DECRYPT(FirstName,  'uk112') "
           + "AS FirstName, AES_DECRYPT( MiddleName,  'uk112') "
           + "AS MiddleName, AES_DECRYPT(LastName,  'uk112') "
           + "AS LastName, DOB, AES_DECRYPT(Gander,  'uk112')"
           + "AS Gander, AES_DECRYPT(Address,  'uk112')"
           + "AS Address, AES_DECRYPT(City,  'uk112' ) "
           + "AS City, AES_DECRYPT(PostCode,  'uk112')"
           + "AS PostCode FROM Customer";
   pst = conn.prepareStatement(sql);
   rs =pst.executeQuery(sql);
   CTable.setModel(DbUtils.resultSetToTableModel(rs));
   pst.close();
   rs.close();
  }
  catch(Exception e){
 JOptionPane.showMessageDialog(null, e);
  }   
  }

whenever i try call the Update_Table method in order to update The JTable this happens

enter image description here

mKorbel
  • 109,525
  • 20
  • 134
  • 319
mohamed nur
  • 331
  • 1
  • 15
  • have you tried geting data from `rs` like `rs.getString("FirstName")` ? does it give `encryped` data or `decrypted`? if it gives `encypted` data, is it possible that you encypted data twice while inseing to DB? if it gives `decrypted` data can you show us code of `DbUtils`? If it gives – rahul maindargi Apr 24 '13 at 17:22
  • I have only encrypted the data once, but how would use 'rs.getString("FirstName")' – mohamed nur Apr 24 '13 at 17:36
  • after ` pst = conn.prepareStatement(sql); rs =pst.executeQuery(sql);` use `while(rs.next()){String name=rs.getString("FirstName"); System.out.println(name);}` and check console – rahul maindargi Apr 24 '13 at 18:30
  • It decrypts it .... by the way thanks for your effort – mohamed nur Apr 24 '13 at 19:35
  • Then may be you are encoding it inside DbUtils.resultSetToTableModel somehow. if you can show code snippet of that we wil be able to help. – rahul maindargi Apr 25 '13 at 09:41

1 Answers1

1

It's probably not still encrypted. That's the expected output of the default renderer. As shown here, the result is produced by toString() invoked with a byte array. In your custom renderer, you can convert the array to a String using a suitable constructor, but you'll need to specify the same encoding used by the database.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045