Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

embedding spaces in java

Posted on 2013-06-18
10
Medium Priority
?
212 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 1600 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

885 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