• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem on saving string path in database  RSS feed

 
Tan Joey
Greenhorn
Posts: 8
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm doing a project on saving a string which is a path name like, "C:\Desktop\<folder name>" 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\<folder name>" but in the database column for this path it only store "C: Desktop<folder name>", without the '\' so i having problem solving this problem to store the path in this format, "C:\Desktop\<folder name>". As i have try using delimiter or split like this, 'String[] a = fingerPath.toString().split("\\");' or 'useDelimiter("\\");' but the state this error , Unexpected internal error near index 1 \ . Any help will be appreciated thank you.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Definitely not GUI related. Since I don't think the problem is in the database part either I'll move this thread to Java in General.
 
Steven Bruton
Greenhorn
Posts: 13
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You did not specify what DBMS you are using but if it is MySQL (I'm not too sure about others) you'll need to format the string like so;

"C:\\\\Desktop\\\\<folder name>"

The compiler will read this as "C:\\Desktop\\<folder name>" so this will be the string used in the update/insert
During insert/update this will be read as "C\Desktop\<folder name"
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That sounds reasonable. Guess it was a database problem after all.

This is also why I prefer to use PreparedStatement. That does all the escaping for me. I think I assumed a PreparedStatement was used.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!