Solved

embedding spaces in java

Posted on 2013-06-18
10
206 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

Title # Comments Views Activity
jdbc error in jsp application 20 71
CSV file parsing thru Java 13 39
Bot application - advice 3 58
hashmap order 17 40
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…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
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 …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

680 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