简体   繁体   中英

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 '\\'

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

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

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.

您可以尝试使用正斜杠(即“ C:/ Desktop /”)存储它

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM