Solved

embedding spaces in java

Posted on 2013-06-18
10
201 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 74

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
 
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

746 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now