• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

storing data with slashes

Ranch Hand
Posts: 172
Netbeans IDE PHP Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ranch!

I am a struggling rookie on jdbc and sql. I have a project in which i am trying to store filepaths to images located in a folder on
the following location K:\francine\src\resources\images\. I am using netbeans for this project. My question is how do i store data
with slashes in a mysql table column? I have tried it with the sql below but it's not working and i am clearly missing something
big here.

When i execute the above insert query in mysql with a command line tool all i see is underscore characters instead of
forward slashes.

Further on i wan't to store filepaths selected from a JFileChooser in the table mediatype_tbl so i am curious about this problem
and i am very thankful for any kind of helpful reply or hint.

Best regards,

Posts: 25594
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The backslash is the standard escape character in MySQL; I suggest you read 9.1.1 String Literals for complete information about how that works and how to deal with it.

However you referred to the \ character in your post variously as "slashes" and "forward slashes". The character \ is referred to as "backslash" by computer programmers and / is "forward slash". It helps if you make a clear distinction here.

And in your proposed Java code where you get a path from a JFileChooser, I believe you don't need to worry about this issue. Every JDBC driver is designed to understand how to deal with its variety of SQL and its features, such as escape characters. Using a PreparedStatement to run the INSERT statements you described would automatically take care of escaping things which need to be escaped.
Saloon Keeper
Posts: 22111
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Those are not "slash" characters. A slash, also known as a virgule, solidus or stroke faces the other direction, thus: /

The slash has a long and honorable history, having been used as punctuation and as a currency symbol in historical English coinage, where it indicated shillings.

The backslash appears to be a recent invention, not in common use until it was made part of the ASCII character set in 1961.

Pedantry aside, the backslash is a "magic" character, used as a graphical escape indicator. For example, "\n" is compiled into the non-printable "newline" character (ASCII and Unicode hex value 0x0A). To switch off its meaning, you have to double up like this: "\\", which compiles to a single backslash, and that is what you would have to do for your data.

You should be aware that Java supports a normalized filename convention, and will happily accept the alternative syntax of "K:/francine/src/resources/images/icon_bluray.jpg". This also works for Windows in some cases, although I haven't seen a simple rule that explains where. Note that this format does not compile into DOS/Windows format, though. It's exactly as coded, so apps that aren't written in Java may not accept them.

Beyond that, I would avoid storing too much of the path information in a database. If you later want to move the files to some other directory or make them visible from some other source, the full path might not work. So as a rule, keep the root parts of the patch separate from the sub-directory structure of the files themselves.
Do Re Mi Fa So La Tiny Ad
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic