Solved

report with apostrophe does not get inserted in database

Posted on 2001-06-15
3
407 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 50 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ejb stateless example 2 42
Adding multiple JVM environments to RedHat 6 7 69
how to debug htl and js pages 8 54
Netbeans and org.apache.commons.lang3 issue 3 24
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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 …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

756 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