?
Solved

report with apostrophe does not get inserted in database

Posted on 2001-06-15
3
Medium Priority
?
420 Views
Last Modified: 2010-03-31
hi,
i'm facing a problem in inserting a small report in the database. The error occurs whenever the record encounters an apostrophe in the contents otherwise it gets inserted properly.
How do i handle it.I 've read it is possible to replace the apostrophe with escape characters so that they are inserted properly in the database.
could anybody tell me how to convert each occurence of an apostrophe to escape characters in a report.kindly give me the codes if possible.
I'm working in java servlets.thanx .its very urgent.
0
Comment
Question by:ManojKumar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 

Accepted Solution

by:
Nachiap earned 200 total points
ID: 6197602
try this....;-)

public static synchronized String validateQuery( String str)  {
          int newSize=2;
          char[] strArray = str.toCharArray();
          char[] repairedArray;
          while (true)  {
               try  {

                    repairedArray = new char[strArray.length*newSize];
                    for(int i=0,j=0;i<strArray.length;j++,i++)  {
                         char c=strArray[i];
                         repairedArray[j]=c;
                         if(c=='\'') {
                              j++;
                              repairedArray[j]='\'';
                         }
                    }
               } catch(ArrayIndexOutOfBoundsException ae)  {
                    System.out.println("New array size was not enough.  No worry.  Trying with increased size");
                    newSize++;
                    continue;
               }
               break;
          }
          return new String(repairedArray).trim();
     }

usage : <ClassObject>.validateQuery("There's")
0
 
LVL 3

Expert Comment

by:superschlonz
ID: 6198115
If you use the setString method of PreparedStatement you shouldn't get this
error. Do it like this:

Connection conn = DriverManager.getConnection( "..." );
PreapredStatement ps = conn.prepareStatement( insert into x ( a, b ) values ( ?, ? )" );
ps.setInt( 1, 42 );
ps.setString( 2, "what's that" );
int rowcount = ps.executeUpdate()
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 8950685


No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:


-- points to Nachiap


Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
sudhakar_koundinya
EE Cleanup Volunteer
---------------------
If you feel that your question was not properly addressed, or that none of the comments received were appropriate answers, please post your concern in THIS thread.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses
Course of the Month15 days, 6 hours left to enroll

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question