[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

report with apostrophe does not get inserted in database

Posted on 2001-06-15
3
Medium Priority
?
437 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 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month19 days, 12 hours left to enroll

872 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