Tuesday, 21 May 2013

Remove Carriage return in varchar column in sql


I have a mysql table with VARCHAR column which contains String values. Sometimes at the end of the string there is a carriage return (\r). I only want to delete the \r at the end of the string if it exists.


A carriage return is CHAR(13)

The following code will remove Carriage return 

UPDATE table_name set column_name=REPLACE(column_name,char(13),'')

Remove a character from a string in mysql


I have a mysql table with a column name "sequence". sequence column contains protein sequence starting with "protein name > sequence letters"
I need to remove the characters left to ">" including >

for eg: for the input sequence 
the output should be


You can use SUBSTRING_INDEX(str,delim,count

SUBSTRING_INDEX returns the substring from string str before count occurrences of the delimiter delim. If count is positive, everything to the left of the final delimiter (counting from the left) is returned. If count is negative, everything to the right of the final delimiter (counting from the right) is returned. SUBSTRING_INDEX() performs a case-sensitive match when searching for delim.

you can use

update table_name set column_name = SUBSTRING_INDEX(column_name, '>', -1);

Trim all the values in a column in a sql

Trim all the values in a column in a sql

SQL does not have a trim function. You'll need to use RTRIM and LTRIM together.
update MyTable set Name = RTRIM(LTRIM((name))

Thursday, 16 May 2013

java.lang.classnotfoundexception com.mysql.jdbc.driver in jsp


When i try to have simple jdbc connection to mysql  in my jsp file, i get following console output in eclipse:
console output in eclipse:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

When i tried to have the same kind of connection from a simple java file it was working.


You should put the mysql connector JAR file in WEB-INF/lib directory of your project. Clean Build the project and restart the server.

Add Mysql connector in eclipse classpath

Add Mysql connector in eclipse classpath

1. Download mysql connector jar from
2. Open eclipse in java EE perspective (top right corner)
3. Right click the project go to Properties.
4. Choose Java Build Path and then Select Libraries tab
5. Click Add External JARs  and add the path of the mysql connector jar
6. Click Ok button and clean and build the project

Properties window for my java project

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver error


When I try connect my java program to mysql database using eclipse,i am getting the run time error
 "java.lang.ClassNotFoundException: com.mysql.jdbc.Driver"


The reason for the error is you don't have mysql-connector.jar in your Classpath. This jar
contains "com.mysql.jdbc.Driver" class and it must be present in java classpath in order to successful connection to mysql database.
you can downlad mysql-connector.jar from

Click here for adding mysql connector jar to eclipseclass path

Wednesday, 15 May 2013

Php mail tagged as Spam in Gmail Issue fixed


When I send mail using PHP mail() function,the mail is sent to the Spam folder in GMail.


You can fix this issue by using the fifth parameter in the mail function to build the header with a valid From address.

PHP Code


$from 'you@yourserver.com';

$message 'Hello';

$subject 'Test Mail';

mail($to$message$subject"From: $from""-f$from");