Fab
Fab

Reputation: 1215

How to store special characters in Oracle table?

I want to insert in a Oracle table a string representing a HTTP request, such as:

a=5&b=hello&date=2016/01/01

Here my Java code:

//HttpServletRequest request comes in to the server
String url = request.toString().substring(beginIndex, endIndex);
stmt = conn.prepareStatement("INSERT INTO table (URL) VALUES (?)");
stmt.setString(1, url);
stmt.executeQuery();
stmt.close();

Currently, this string is automatically stored as follows:

a=5&b=hello&date=2016%2F12%2F31

that is, as UTF-8 encoded string.

Is there a way to store it "AS IS" rather than in URL encoded form?

Thanks

Upvotes: 1

Views: 569

Answers (1)

MT0
MT0

Reputation: 168588

The string is URL encoded, you can use URLDecoder.decode( urlstring, encoding ) to decode it before passing it to the database:

String url = URLDecoder.decode(
               request.toString().substring(beginIndex, endIndex),
               "UTF-8"
             );

Upvotes: 2

Related Questions