Tuesday, September 1, 2009

Use uppercase letters for mysql data table names in Windows

When we developing mysql based applications, there is a good probability to developers develop the application on Windows OS and deploy it on a linux server or vice versa. MySQL supports both lowercase and uppercase letters for table names in unix enviroments, but when it came to Windows, the default MySQL configuration does not support upper case letters in table names. This becomes a big headache if you need to restore mysql database backups from windows environments to unix environments ( other way round is not quiet a problem since all table names becomes lowercase in Windows machines) during several times while development.

Today I found a solution for this case insensitvity of table names in MySQL servers on Windows environment. There is a mysql system variable called "lower_case_table_names" and it has set to 1 in default mysql configuration for Windows. 1 means only lower case table names are supported. For gaining the support for Both lower and upper case letters in table names, what you have to do is find relevant my.ini file for your MySQL installation and add the following line to the end of the file.
lower_case_table_names=2
Then restart the MySQL server. Now you will be able to create tables with names which include both upper-case and lower-case letters.

Related MySQL articles,
http://dev.mysql.com/doc/refman/5.0/en/identifier-case-sensitivity.html
http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_lower_case_table_names

Saturday, July 18, 2009

Searching a MySql database for a Value to find which tables contains it.

In my recent works, I needed to do a search for a some string value to find what are the tables contains that value. Although there are easy tools and methods which allows you to search for a value in a known field and known data table, I couldn't found a easy way to search for a value in a entire MySQL database. So i wrote this simple PHP script for accomplished that task. If somebody needs such functionality, they can use the script. Please change the database host, user name, password ( and database name ) according to your requirements.

This scripts helps to search a value in an entire mysql database. In main results page, it will displays the tables which contains the search value and what are the fields which contains the search value and number of occurences of the search value. By clicking on the number of results column value in the main results table, You can go to a page which displays the rows which contains the search value in relevant database table.

Download it from
http://heidisoft.com/sites/default/files/phpmysearch.zip
or
http://rapidshare.com/files/257172086/phpmysearch.zip

Sunday, July 5, 2009

Reset passwords for XAMPP pages

When I installed XAMPP on UBUNTU OS in my laptop, I put a password for that. But unfortunately , I couldn't remember it later. So I did some search on it and found a solution for the problem.

Open a terminal and type following command,
sudo /opt/lampp/lampp security
Then it will ask for new password and no need to provide old passwords.

Wednesday, April 22, 2009

Upload a file to another webpage through a Java Servlet

In past few days, I had to work on implementing a functionality for sending an HTTP request to another url and upload a file with that HTTP request and then get the response for the HTTP request from a Java servlet. This is the code I finally created for achieving my task. It does,
  1. Connect to another given URL
  2. Upload given string as a file to the above url
  3. Then read the response for the above HTTP request.
Below function is called inside the protected void processRequest(HttpServletRequest request, HttpServletResponse response) of a Servlet in my project. I have put the relevant code for achieving this task in below.

// Import these packages
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;

// Code
private String uploadFile(String urlstring, String dataXML) {
try {
 String itemname = "formFile"; String tempfilename = "test.xml";  String lineEnd = "\r\n";  String twoHyphens = "--";
 String boundary = "---------------------------24464570528145";
 URL url = new URL(urlstring);
 HttpURLConnection connection = (HttpURLConnection)  url.openConnection();
 connection.setDoOutput(true);
 connection.setDoInput(true);

 connection.setUseCaches(false);
 


 connection.setRequestMethod("POST");

 connection.setRequestProperty("Connection", "keep-alive"); 

 connection.setRequestProperty("Content-Type", "multipart/form- data; boundary=" + boundary);
 connection.setRequestProperty("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
 


 DataOutputStream dataoutputstream = new          

     DataOutputStream(connection.getOutputStream()); 

 dataoutputstream.writeBytes(twoHyphens + boundary + lineEnd);

 dataoutputstream.writeBytes("Content-Disposition: form-data;    name=\"" + itemname + "\"; filename=\"" + tempfilename + "\"" +  lineEnd);

 dataoutputstream.writeBytes("Content-Type: text/plain" +  lineEnd + lineEnd);
 // dataXML is File data, writes a string as the file content of  the uploading
 // file
 dataoutputstream.writeBytes(dataXML);
 dataoutputstream.writeBytes(lineEnd);

 dataoutputstream.writeBytes(twoHyphens + boundary + twoHyphens +
lineEnd);


 dataoutputstream.flush();
 dataoutputstream.close();

 String inputLine;
 StringBuffer sbResponseData = new StringBuffer();


 // Get the response data for the previous HTTP request

 DataInputStream dis = new  DataInputStream(connection.getInputStream());
 while ((inputLine = dis.readLine()) != null) {
  sbResponseData.append(inputLine + "\n");
 }

 dis.close();
 return sbResponseData.toString();


 }
 catch (Exception ex) {
  logger.error("Exception in initiating outdial call request:       Details: " + ex.toString());
 }

}

Wednesday, April 15, 2009

Previewing the URL of a TinyUrl

Nowadays, many of us use TinyURL s instead of using long urls for the ease of use. Think that a site you visited has a tiny url like http://tinyurl.com/c8yvgr. We can not directly say whether this tiny url links to a good site or a porn site or a other malicious site by looking at given tiny url . But now you can preview the actual URL before visiting the target site using a feature provided by http://tinyurl.com. What you have to do is go to http://tinyurl.com/preview.php and then click on the link Click here to enable previews. After enabling that, each time you click on a tinyURL, it will first show the preview of actual url and then you can proceed as you wish. You can later disable the preview settings using the same page.

Wednesday, April 8, 2009

How to get auto generated field values (primary keys etc) after inserting a data entry to the database [ for PostgreSQL]

In these days I'm involved with a project using a PostgreSQL database. This is the first time I'm working with PGSQL, So I could learn some new features in PGSQL. One of the requirement I needed while coding is to find an easy way to get the auto generated primary key value when inserting a data record to the PGSQL database. I could find several ways to do that and one of method I found was really easy way. Those methods I found are described in this post.

First Method:
public int insertData( String name, String address, String tp_no)
{

int insertedKey = 0;
try {
Class.forName("org.postgresql.Driver");
Connection con = DriverManager.getConnection("jdbc:postgresql://localhost/MyDb", "username", "password");

// Database has a primary key named "recordId"
String insertSql = "INSERT INTO \"MyTable\" (name, address, tp_no)" + " VALUES (?, ?, ?);";
PreparedStatement pstmt = con.prepareStatement(insertSql);
pstmt.setString(1, name);
pstmt.setString(2, address);
pstmt.setString(3, tp_no);
pstmt.executeUpdate();

// each table has a sequence named "TABLENAME_PRIMARYKEY_seq"
// my table name is "MyTable" and it has the auto incremented
// primary key field called "recordId". So sequence related to
// following query is "MyTable_recordId_seq"
String getRecordIdSql = "select currval('\"MyTable_recordId_seq\"');";
Statement stmtGetRecId = con.createStatement();
ResultSet res = stmtGetRecId.executeQuery(getRecordIdSql);

if (res.first())
{
insertedKey = res.getInt(1);
}

con.close();

}
catch (Exception e)
{
System.out.println("Exception occurred: Details: " + e.getLocalizedMessage());
}

return insertedKey;

}

Second & Easy Method:

public int insertData( String name, String address, String tp_no)
{

int insertedKey = 0;
try {
Class.forName("org.postgresql.Driver");
Connection con = DriverManager.getConnection("jdbc:postgresql://localhost/MyDb", "username", "password");
// See the end of the query string
// Database has a primary key named "recordId"
String insertSql = "INSERT INTO \"MyTable\" (name, address, tp_no)" + " VALUES (?, ?, ?) RETURNING recordId;";
PreparedStatement pstmt = con.prepareStatement(insertSql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
pstmt.setString(1, name);
pstmt.setString(2, address);
pstmt.setString(3, tp_no);
ResultSet res = pstmt.executeQuery();
// Get record id of the newly inserted record
if (res.first()) {
insertedKey = res.getInt(1);
}
res.close();
con.close();
} catch (Exception e) {
// logging
System.out.println("Exception occurred: Details: " + e.getLocalizedMessage());
}
return insertedKey;

}

Another Method:
I found later an another way to get the generated keys using JDBC, but I didn't have time to test that. But you can find an example to that method in this article http://www.java-tips.org/other-api-tips/jdbc/how-to-get-auto-generated-keys-from-java-class-3.html

Wednesday, April 1, 2009

Show hidden files even when computer is infected by a virus

You can show the hidden files by changing this entry even in a machine infected by a virus. There is another place in the registry that can use to show/hide hidden files, but when the computer is infected by a virus, it doesn't work. This method still works in this situation.
+HKEY_LOCAL_MACHINE
+SOFTWARE
+Microsoft
+Windows
+CurrentVersion
+Explorer
+Advanced
+Folder
+Hidden
NOHIDDEN
In the NOHIDDEN folder, select CheckedValue and set value to 1.

Wednesday, September 10, 2008

Love ( A poem by Hafiz )

Even after all this time
The sun never says to the earth "you owe me".
Look what happens with a Love like that!
- It lights the whole Sky.
-By Hafiz


This is really a wonderful poem. I think it has the real meaning of love.

Tuesday, May 13, 2008

UoM wins GSoC First Place

When I read my emails in today morning I found an amazing news. It's about GSOC 2008. It says the largest number of GSOCers in this year are from my university, University of Moratuwa. Hey friends, It is cool.

Read this blog for more info.
http://google-opensource.blogspot.com/2008/05/this-weeks-top-10s-universities-for.html

Tuesday, March 18, 2008

Sir Arthur C. Clarke : A Great Man in Our Age, has passed away


When I was a child, I was fascinated by the beauty of the sky. Sky was a real mystery which hide beautiful secrets to me. Moon, sun, stars, comets, meteors, these were really great things that attracted me and saw me a path to a hidden world full of secrets, mysteries. There was one person who helped me to go beyond my imagination about space and its secrets. I began to love sky, astronomy, and was curious to find its secrets because of that great man. He was a great philosopher, a great scientist, and a great author. He had his imagination beyond many of men in his generation (many sci-fi writers has this ability). I can describe him as a great man of our age. Many technologies that changed the world were his brain children. Famous example for his ideas that used successfully in these days is concept of geostationary satellites use for telecommunications relays. Now you know who I am talking about. Your guess is right. I'm talking about Sir Arthur C. Clarke, a great man of our age.

Once I have read somewhere that science fiction is a super weapon invented by future scientist and it was invented for speed up the development of technology of mankind in order to prepare for future alien attack. (It was also a science fiction :)). Although that was another science fiction, concept of that science fiction is right. Actually science fictions written by those great sci-fi writers like Sir Arthur C. Clarke were and are really helping for the progress for science and technology. Science fictions helps science and technology to get close to common peoples without knowing much theory and complex concepts. So science fictions are really a kind of great inventions made by man. If you have read, you know that Science fictions written by Sir Arthur C. Clerk are really great. Those sci-fi novels written by Sir Arthur C. Clerk are not some fancy thinking of a day dreamer. Those novels are written on scientific facts and incidents that can happen in the future. In his every novel there is something new interesting story in there. When I were at grade 8 and 9, my pals were very addicted in reading his sci-fi novels, especially series of Space Odyssey, from "2001 A Space Odyssey" to "3001 The Final Odyssey".

I was very proud because he is a citizen of my country, Sri Lanka. He was the vice chancellor of my university, University of Moratuwa until 2004, but unfortunately he retired before I enrolled my BSc (Eng.) course in there. He was a great scientist who help the world to travel through time to few years ahead of its development. He was a great thinker who changed the world by his concepts. He was a great sci-fi writer who helped to taking science and it's concepts to common people. He is a great man. I proud to say I was living in the age of Sir Arthur C. Clarke.

What I heard first in today morning, was a very sad news. That's why I wrote this post about one of great man of our age, Sir Arthur C. Clarke. Today, that great man, Sir Arthur C. Clarke has passed away. My heart shocked by that news. I know, not only my heart. Hearts of thousands of people who know the worth of this great man, were shocked by this sad news. I think he should not die, He should live more years to see how his imaginations comes true. I wish the highest and noblest wish of my religion. May Sir Arthur C. Clarke attain nibbana.


These are some of books by Sir Arthur C. Clarke I have read

  • 2001 A Space Odyssey
  • 2010 Odyssey Two
  • 2061 Odyssey Three
  • 3001 The Final Odyssey
  • A Fall of Moon dust
  • Childhood's End
  • Cradle
  • Reach for Tomorrow
  • Rendezvous With Rama
  • Dolphin Island
  • The Fountains of Paradise
If you want to learn more about him go to
http://en.wikipedia.org/wiki/Arthur_C._Clarke

http://www.clarkefoundation.org/acc/biography.php