Reputation: 1215
I want to perform an INSERT operation into an Oracle DB table.
A sample string I want to insert is a HTTP request:
a=5&b=hello&date=2016/12/31
This string is stored as follows:
a=5&b=hello&date=2016%2F12%2F31
that is, using URL encoded characters rather than UTF-8 encoded string.
Previously, my string was stored in UTF-8 format as expected. So, I was able to retrieve and process it using
string.split('/')
What is the issue? What could be changed in my development environment? Is this an issue DBMS-side?
Thanks
EDIT:
public static String func(HttpServletRequest request) {
String date = request.getParameter("date");
date.split("/"); IT WORKS!!!
}
public static String func(String url_stored_into_DB) {
String date = getDateFromUrl(url_stored_into_DB);
date.split("/"); IT DOESN'T WORK!!!
since it was stored with %2F
}
To store the url into the DB:
//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();
Upvotes: 0
Views: 107
Reputation: 108796
You're trying to split a text string that contains no '/' characters using the '/' character. Of course it doesn't work. Why do I say your string contains no '/' characters? Because it is URL encoded. The purpose of URL encoding is to make sure the string doesn't contain various characters that have meaning in URLs.
You need to URL decode it first. Something like this should do the trick.
String date = getDateFromUrl(url_stored_into_DB);
date = java.net.URLDecoder.decode(date, "UTF-8");
date.split ("/");
Upvotes: 4