achour nidhal
achour nidhal

Reputation: 3

Save string path in a database

Java MySQL Database I'm doing a project on saving a string which is a path name like, "C:\Desktop\" into the database. I had create a entity class to update this path name into database, in java eclipse when i run my program it display the path is store in the database in this format, "C:\Desktop\" but in the database column for this path it only store "C: Desktop", without the '\'

Upvotes: 0

Views: 707

Answers (4)

Stimpson Cat
Stimpson Cat

Reputation: 1508

A simple solution is to replace the the "\" before you store it in the database. Try:

string.replace("\","@");

Then your slashes are the @ symbols. When you read the value again, you can do it the other way.

Upvotes: 0

Rahul Winner
Rahul Winner

Reputation: 430

you may try storing it with forward slash i.e. "C:/Desktop/"

Upvotes: 0

Ruchira Gayan Ranaweera
Ruchira Gayan Ranaweera

Reputation: 35587

Simplest solution is use / instead of \ in path . Or escapes the characters in a String using Java String rules

Upvotes: 1

Juned Ahsan
Juned Ahsan

Reputation: 68715

You need to escape the \ with \\. Use this to store

C:\\Desktop\\

instead of

C:\Desktop\

Learn more about escape sequence in java : http://docs.oracle.com/javase/tutorial/java/data/characters.html

Upvotes: 1

Related Questions