Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML
 
 
Hot Web Programming Job

 

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML


 

Search Host

Monthly Fee($)
Disk Space (MB)
Register With us for Newsletter!
Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Have tutorials?
Add your tutorial to our Java Resource and get tons of hits.

We offer free hosting for your tutorials. and exposure for thousands of readers. drop a mail
roseindia_net@yahoo.com
 
   

Tutorials

Java Server Pages

JAXB

Java Beans

JDBC

MySQL

Java Servlets

Struts

Bioinformatics

Java Code Examples

Interview Questions

 
Join For Newsletter

Powered by groups.yahoo.com
Visit Group! Post Questions!

Web Promotion

Web Submission

Submit Sites

Manual Submission?

Web Promotion Guide

Hosting Companies

Web Hosting Guide

Web Hosting

Linux

Beginner Guide to Linux Server

Frameworks

Persistence Framework

Web Frameworks

Free EAI Tools

Web Servers

Aspect Oriented Programming

Free Proxy Servers

Softwares

Adware & Spyware Remover

Open Source Softwares

Adding slash "\" character before quote "'" in a query 



During the inserting the records in the database if user enters the phrases like "What's your name?", database gives the error due to the presence of the "'" quote. So it is necessary to add slashes before the quote. For example if the user enters "What's your name?" then we will have to change it to "What\'s your name?" by placing the "\" character before the quote "'". Following program do this:


import java.util.*;

public class quote{

public String addSlashes(String str){
if(str==null) return "";

StringBuffer s = new StringBuffer ((String) str);
for (int i = 0; i < s.length(); i++)
if (s.charAt (i) == '\'')
s.insert (i++, '\\');
return s.toString();

}

public static void main(String args[]) {
quote qt=new quote();

System.out.println(qt.addSlashes("What's your name?"));
}

}


If you run the above code addSlashes function will add slashe ("\") before the quote "'" and the out put will be shown on the console.


You can use the following function in your java application to add the slashes.


public String addSlashes(String str){
if(str==null) return "";

StringBuffer s = new StringBuffer ((String) str);
for (int i = 0; i < s.length(); i++)
if (s.charAt (i) == '\'')
s.insert (i++, '\\');
return s.toString();

}


Next time I will show you how to use this in java applications.


Useful Links
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.