Monday, April 20, 2009

sql IN logical operation for java

Hi,
have you ever needed sql IN for java language ?
OK, in this post I'm going to use new java 5 feature (varargs method) to simulate sql IN:
public static boolean in(int i, int... ints) {
Arrays.sort(ints);
return Arrays.binarySearch(ints, i) >= 0;
}
as you see, our function gets 2 parameters, first one is your desired value and second one is your search list.
now, when you call the method:
public static void main(String[] args) {
System.out.println(in(1, 2, 3, 4, 5, 1));
}
it returns:
true
i hope you find this tip useful;

Labels:

Saturday, April 11, 2009

backup from mysql database's routines

Sometimes we need get backup just from mysql database's routines.
command below shows us how we can do that:
mysqldump dbname -uusername -p -Rtd > /path/to/your/dump/file

-u username
-p prompt password
-R stored procedures and functions
-t prevent writing table creation
-d " " row information

Labels: ,