Solved

embedding spaces in java

Posted on 2013-06-18
10
205 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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…
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…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

856 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