Solved

report with apostrophe does not get inserted in database

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Java virtual machine monitoring tools 3 39
copyEndy  challenge 15 58
JDeveloper 12c for 32 bit 4 36
GUI builder for Eclipse? 8 13
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…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now