Solved

embedding spaces in java

Posted on 2013-06-18
10
204 Views
Last Modified: 2013-06-19
I have the following declaration:

List<String> commandList = new ArrayList<String>(){{
        ...
       add("last_name=\"Test User\"");

   }};

I want to make sure Test User is inserted into my database w/o the quotes but its not working.  Any ideas?
0
Comment
Question by:chuckster_eh
  • 3
  • 2
  • 2
  • +2
10 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39257380
Without seeing your database code, it would be difficult to tell you where you're going wrong. Make sure you are single-quoting your strings that go to the database.

e.g.

string toDatabase = "'Test User'";  // single quotes surrounding string; double-quotes surrounding single quotes

Open in new window

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39257490
I want to make sure Test User is inserted into my database w/o the quotes
Why not just replace them then?

s = s.replaceAll("\"", "");

Open in new window

0
 
LVL 37

Accepted Solution

by:
zzynx earned 400 total points
ID: 39258746
Your java code looks OK.

Question is: what does the code that is responsible for the database insert do with the command:

                    last_name="Test User"


>> I want to make sure Test User is inserted into my database w/o the quotes
>> but its not working.
Do you mean that it is currently inserted with the quotes?
Then why not trying:

        add("last_name=Test User");

Open in new window

0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 16

Expert Comment

by:Valeri
ID: 39259007
probably the value is taken in this way...?!?!
String[] arrValues = theWholeString.split("=");
and arrValues[1] is inserted to database, so try with this line, the same like original one, but without the quotes :
add("last_name=Test User");
0
 
LVL 37

Expert Comment

by:zzynx
ID: 39259036
@Valeri: that's exactly what I said in the previous comment
0
 
LVL 16

Expert Comment

by:Valeri
ID: 39259201
@zzynx: yes, it's almost the same! if this is the case you will be the awarded one, because you were the first one with the idea! :-)
I wrote this because sometimes it's not easy for the begginers to trace the code in the way that experienced developers can.
0
 

Author Closing Comment

by:chuckster_eh
ID: 39260933
Thank you.  This was the syntax that ended up working for me.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39261141
Q. How do i get a string inserted into the db without quotes
A. Don't put them in

;)
0
 

Author Comment

by:chuckster_eh
ID: 39261161
very true it turned out to be in this case.   :)
0
 
LVL 37

Expert Comment

by:zzynx
ID: 39261613
Life can be easy ;-)
Thanx 4 axxepting
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
custom annotations 9 39
javap bin 2 34
Problem to open text file 11 110
expectj telnet failing 5 36
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

810 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