Xubuntu – Time Synchronization
In xubuntu (XFCE) you can run the following command to synchronize your system clock with time servers:
sudo ntpdate pool.ntp.org
After running this command you would get a response similar to the following:
21 Aug 04:08:20 ntpdate[4824]: adjust time server 209.167.68.100 offset 0.017300 secRead More
Struts2 Iterating through a List of List
This is a simple example demonstrating how to use the iterator tag in struts2 to iterate through a list of objects which contains another list of objects.
Assume that we have a class called City which contains a list of phone numbers:
public class City {
private String name;
private List<PhoneNumber> phoneNumbers;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<PhoneNumber> getPhoneNumbers() {
return phoneNumbers;
}
public void setPhoneNumbers(List<PhoneNumber> phoneNumbers) {
this.phoneNumbers = phoneNumbers;
}
}
Read More
Plain-text encryption/decryption in Java
There could be cases in which you are planning to keep some sensitive data in your database but you do not wish to have this information available to anyone (not even the DBA should be able to see the content) except the specific user. To do this you can encrypt the sensitive plan-text provided by the user. Save the encrypted message in the database and decrypt it anytime the user would like to view/edit the data. Doing this is quite easy with java. You would just need to add a few jar files to your project and a few lines of code to encrypt and decrypt the data.
The libraries you need to download are available at: http://www.jasypt.org/
The following sample code encrypts and decrypts a String. Please not that I have created an object of BasicTextEncryptor twice the reason for that is to show that you would need to set the correct password used in the encryption process to decrypt the plain-text message.
import org.jasypt.util.text.BasicTextEncryptor;
public class Secret {
public static void main(String[] args) {
String userPassword="PassWord";
String message = "Some text which is to be encrypted by the user password. Later it is decrypted to the original plain-text using the same password.";
//Encrypt
BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
textEncryptor.setPassword(userPassword);
String myEncryptedText = textEncryptor.encrypt(message);
System.out.println("Encrypted text:\n"+myEncryptedText);
//Decrypt
BasicTextEncryptor textDecryptor = new BasicTextEncryptor();
textDecryptor.setPassword(userPassword);
String plainText = textDecryptor.decrypt(myEncryptedText);
System.out.println("Decrypted text:\n"+plainText);
}
}
Read More
Inserting/Update a long String into a CLOB in Oracle database
Inserting a long String into a CLOB field in Oracle database using SQL queries is quite simple, but at the same time can be confusing. Mainly because personally couldn’t find good tutorials on the web when I was trying to do this. Here is a simple way to do it:
To insert a ClOB field you need to have a good query browser. The reason is that I will be using variables to do this, I was not able to do this using DbVisualizer but it works perfectly fine in TOAD.
Here is how to do it:
-- First: you need to declare a variable to hold the long CLOB value. declare clobVariable varchar2(32767) :='YOUR LONG CLOB VALUE GOES HERE'; begin -- ALL the queries you need to run as to be inside the begin tag. -- As you can see I'm using the variable 'clobVariable' in the insert statement to insert into the table. -- You can use this variable in any combination of SQL statements. insert into sometbale(id,clob_column) values(1,clobVariable); end; /Read More
XFCE – XUBUNTU
First time I installed xfce on my laptop I was surprised with how light and stable it was. I have been using XFCE for more than 2 years now I would have to say that its great. I would strongly recommend it specially if you don’t have a really powerful machine like me. To customize it the way you like its obviously a little different from Gnome but once you can used to it you would see how easy it is. Here is a screen-shot of my desktop:

Ubuntu change computer name
If you would like to change your computer name in Ubuntu Linux you would need to modify two files:
First you would need to change hostname file:
sudo vi /etc/hostname
This file contains your existing computer name. You can change it to anything you like.
The next step is to modify the hosts file:
sudo vi /etc/hosts
Inside this file look for the entry starting with:
127.0.1.1
You would need to change the name in this line to whatever you change to in the first file name.
If you don’t do the second step your computer name would still be changed but you would get the error message “unable to resolve host” everything you login to your account.
SQL insert row if doesn’t exist
There are cases in which you like to insert rows into the database only if it doesn’t exist. There are databases that allow you to insert conditions into the SQL to test the number of rows in the table and insert the new row only of there are no rows currently in the table. But unfortunately you cant do that with many other databases.
Here is a simple way to use regular SQL notations to insert rows into the database table only if it doesn’t exit.
lets assume you have a table called users with the following schema:
| name(varchar) |
| family(varchar) |
| email(varchar) |
lets assume we are interested in inserting a row with the following values only if it doesn’t exist in the database table:
name: Pourya
family: Shahroudi
email: something@something.com
INSERT INTO USERS(name,family,email)
SELECT 'Pourya', 'Shahroudi','something@something.com' FROM USERS
WHERE NOT EXISTS(
SELECT name,family,emial FROM USERS
WHERE name='Pourya'
AND family='Shahroudi' and email='something@something.com'
) and ROWNUM = 1;
As you can see this query does a SELECT on the database table with the values we want to insert if this row doesn’t exist then they are inserted into the database table.
NOTE: “ROWNUM = 1” is extremely important in this query if you don’t have this included the query will try to insert as many records as you currently have in the table into the table.