wood burning stoves 2.0*
The moose likes Java in General and the fly likes Need to parse StringBuffer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Need to parse StringBuffer " Watch "Need to parse StringBuffer " New topic
Author

Need to parse StringBuffer

Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

I have a values filled in ArrayList and also appending some elements inside the StringBuffer



The Output I am Getting is
The String Buffer value is 'Test''Test''Test''Test''Test'

Actually What i want is that while Iterating the ArrayList If i found a NUMBER element i need to remove the Quation Marks

This is waht i am trying .
I don't know how to proceed further plase help .Or tell me is theer any other way to accomplish this .



Please guide me with this or suggest me if there is any easyway to acconplish this task

Thanks in advance .


Save India From Corruption - Anna Hazare.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

That's about it. You can write some class around it (some Format subclass perhaps), but in the end it will still need to check the column types.

But you do know that most database systems allow numerical strings (e.g. '1') to be inserted into a numeric column? I know Oracle does.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Ya ROB you are right , I agree with you , but unfortunately my Manager is not agreeing as this becomes problem if null is passed .

so please tell me any solution .
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

I think I suggested when you asked a simmilar question in a another post - if you want to build a SQL statement why not use a PreparedStatement? That way you don't even need to know what data type the column is, setObject will do the bulk of the work for you. You'll need to watch for nulls, but that is easy, right?

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

I completely agree with Paul on this one. PreparedStatement is the way to go. It will also handle the case where the value already includes quotes.
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

hey Thanks ,

I also go for preparedstatements whenever needed , but here the situation is that the Table name and columns are built dynamically (Means depending on he click of the hyper link)

so it will be some thing like this :





Anyway I completed the task , i will post the code tomorow , so that somebody may use it if required.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Why does the table name being dynamic affect the choice to use Statements over PreparedStatements?
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234


Paul ,
we don't know even the column names also.
Tomorow i will paste the whole code .
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

...again I'm not sure I see what the issue is. You have some sort of meta data (which you are holding in an ArrayList) and you have the table name. That's all you need to build a valid PreparedStatement. Statements (particularaly built up from a web application) are a security hole. If I could use a PreparedStatement over a Statement I would.
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234



May be i followed a wrong approach . Now i don't want to touch that code again and be in headache .
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

You can build your query for prepareStatement using the unknown column names, then use setObject / setNull for setting the actual values.

Still, the security hole still exists. What if I use the following for my first column:
The full query will be this:
I'll let you guess what it will do
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need to parse StringBuffer
 
Similar Threads
string and string buffer
Help!!! Trying to Run Simple Servlet Example.....
String Buffer
Html tag content wrapping
Manipulations with array list.