Solved

report with apostrophe does not get inserted in database

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
firstswap challenge 20 77
ForLoop Example 3 48
difference of if loops 23 49
Which non-HTML GUI front end to use with Java? 3 21
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

776 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