Exposed Kotlin. Problem with cyrillic encoding
I tryed to fix a problem with encodings. So, I sent from 'Postman', from web browser request to server, where I search data in database by keys in request. Request can be like this:
http://localhost:8080/books.getBooksByGenre/Документальное/0/10
(in browser).
Server receive string, like
http://localhost:8080/books.getBooksByGenre/%D0%94%D0%BE%D0%BA%D1%83%D0%BC%D0%B5%D0%BD%D1%82%D0%B0%D0%BB%D1%8C%D0%BD%D0%BE%D0%B5/0/10
then, takes params from url:
genreName: 'Документальное'
start: 0
count: 10.
Then, this data sends to dao:
override fun findGenreByName(genreName: String): DatabaseGenre {
return transaction(db) { getGenreByName(genreName) }
}
private fun getGenreByName(genreName: String): DatabaseGenre {
return try {
val foundGenre = GenreEntity.find { Genres.genre eq genreName }.single()
DatabaseGenre(foundGenre.id.value, foundGenre.genre, foundGenre.link)
} catch (e: Exception) {
throw NothingFoundInDatabaseException("no one genre found by '$genreName'")
} catch (e: NoSuchElementException) {
val m = "Duplicates of genre with name '$genreName'"
throw DuplicatedDataInDatabaseException(m)
}
}
In log I see, that sql-query for finding genres is correct, but I receive an exception:
java.util.NoSuchElementException: Collection is empty.
The sql-query, as I said, is correct:
SELECT genres.id, genres.genre, genres.link FROM genres WHERE genres.genre = 'Документальное'
Structure of genres table:
genres
id: int(10)
genre: varchar(100)
link: varchar(100
I tryied, to select all genres, and this query executed almost correctly. So, I decided, to check this query with english word, and this query correctly executed:
SELECT genres.id, genres.genre, genres.link FROM genres WHERE genres.genre = 'simpleGenre'
I have not exceptions with this query.
So, what I've done wrong and how to fix problem with collations?
UPD:
As I said at github (issue), I've tryied this query it mysql cli and I receive correct answer.
Also, I've tryed to decode url params (with java URLDecoder class). It doesn't helps too.
kotlin orm collate kotlin-exposed
add a comment |
I tryed to fix a problem with encodings. So, I sent from 'Postman', from web browser request to server, where I search data in database by keys in request. Request can be like this:
http://localhost:8080/books.getBooksByGenre/Документальное/0/10
(in browser).
Server receive string, like
http://localhost:8080/books.getBooksByGenre/%D0%94%D0%BE%D0%BA%D1%83%D0%BC%D0%B5%D0%BD%D1%82%D0%B0%D0%BB%D1%8C%D0%BD%D0%BE%D0%B5/0/10
then, takes params from url:
genreName: 'Документальное'
start: 0
count: 10.
Then, this data sends to dao:
override fun findGenreByName(genreName: String): DatabaseGenre {
return transaction(db) { getGenreByName(genreName) }
}
private fun getGenreByName(genreName: String): DatabaseGenre {
return try {
val foundGenre = GenreEntity.find { Genres.genre eq genreName }.single()
DatabaseGenre(foundGenre.id.value, foundGenre.genre, foundGenre.link)
} catch (e: Exception) {
throw NothingFoundInDatabaseException("no one genre found by '$genreName'")
} catch (e: NoSuchElementException) {
val m = "Duplicates of genre with name '$genreName'"
throw DuplicatedDataInDatabaseException(m)
}
}
In log I see, that sql-query for finding genres is correct, but I receive an exception:
java.util.NoSuchElementException: Collection is empty.
The sql-query, as I said, is correct:
SELECT genres.id, genres.genre, genres.link FROM genres WHERE genres.genre = 'Документальное'
Structure of genres table:
genres
id: int(10)
genre: varchar(100)
link: varchar(100
I tryied, to select all genres, and this query executed almost correctly. So, I decided, to check this query with english word, and this query correctly executed:
SELECT genres.id, genres.genre, genres.link FROM genres WHERE genres.genre = 'simpleGenre'
I have not exceptions with this query.
So, what I've done wrong and how to fix problem with collations?
UPD:
As I said at github (issue), I've tryied this query it mysql cli and I receive correct answer.
Also, I've tryed to decode url params (with java URLDecoder class). It doesn't helps too.
kotlin orm collate kotlin-exposed
Well, yeah. That's called URL encoding. If it doesn't automatically decode it, you'll need to do so manually.
– Zoe
Nov 18 '18 at 11:20
@Zoe, thanks for your answer. But, why I saw in logs sql-query with cyrillic letters (in "normal" form)? It was without encoded symbols, just normal cyrillic letters. p.s. I'll try your advice and write here results
– Sergey Grishin
Nov 18 '18 at 14:37
@Zoe, I've tryied your advice. It doesn't hepls. I updated my question description with my attempts to fix this problem and linkto github issue, where I wrote that from mysql cli all works fine
– Sergey Grishin
Nov 19 '18 at 7:59
Do you havecharacterEncoding=utf8
parameter in your MySQL connection URL? Likejdbc:mysql://localhost:3306/db?characterEncoding=utf8
. Another helpful parameter isuseUnicode=true
.
– madhead
Nov 21 '18 at 6:31
1
@madhead, fuu** ghm, it's really works. Thank you very mutch. Spent to this a week. Don't know, how to mark this as correct answer
– Sergey Grishin
Nov 22 '18 at 21:35
add a comment |
I tryed to fix a problem with encodings. So, I sent from 'Postman', from web browser request to server, where I search data in database by keys in request. Request can be like this:
http://localhost:8080/books.getBooksByGenre/Документальное/0/10
(in browser).
Server receive string, like
http://localhost:8080/books.getBooksByGenre/%D0%94%D0%BE%D0%BA%D1%83%D0%BC%D0%B5%D0%BD%D1%82%D0%B0%D0%BB%D1%8C%D0%BD%D0%BE%D0%B5/0/10
then, takes params from url:
genreName: 'Документальное'
start: 0
count: 10.
Then, this data sends to dao:
override fun findGenreByName(genreName: String): DatabaseGenre {
return transaction(db) { getGenreByName(genreName) }
}
private fun getGenreByName(genreName: String): DatabaseGenre {
return try {
val foundGenre = GenreEntity.find { Genres.genre eq genreName }.single()
DatabaseGenre(foundGenre.id.value, foundGenre.genre, foundGenre.link)
} catch (e: Exception) {
throw NothingFoundInDatabaseException("no one genre found by '$genreName'")
} catch (e: NoSuchElementException) {
val m = "Duplicates of genre with name '$genreName'"
throw DuplicatedDataInDatabaseException(m)
}
}
In log I see, that sql-query for finding genres is correct, but I receive an exception:
java.util.NoSuchElementException: Collection is empty.
The sql-query, as I said, is correct:
SELECT genres.id, genres.genre, genres.link FROM genres WHERE genres.genre = 'Документальное'
Structure of genres table:
genres
id: int(10)
genre: varchar(100)
link: varchar(100
I tryied, to select all genres, and this query executed almost correctly. So, I decided, to check this query with english word, and this query correctly executed:
SELECT genres.id, genres.genre, genres.link FROM genres WHERE genres.genre = 'simpleGenre'
I have not exceptions with this query.
So, what I've done wrong and how to fix problem with collations?
UPD:
As I said at github (issue), I've tryied this query it mysql cli and I receive correct answer.
Also, I've tryed to decode url params (with java URLDecoder class). It doesn't helps too.
kotlin orm collate kotlin-exposed
I tryed to fix a problem with encodings. So, I sent from 'Postman', from web browser request to server, where I search data in database by keys in request. Request can be like this:
http://localhost:8080/books.getBooksByGenre/Документальное/0/10
(in browser).
Server receive string, like
http://localhost:8080/books.getBooksByGenre/%D0%94%D0%BE%D0%BA%D1%83%D0%BC%D0%B5%D0%BD%D1%82%D0%B0%D0%BB%D1%8C%D0%BD%D0%BE%D0%B5/0/10
then, takes params from url:
genreName: 'Документальное'
start: 0
count: 10.
Then, this data sends to dao:
override fun findGenreByName(genreName: String): DatabaseGenre {
return transaction(db) { getGenreByName(genreName) }
}
private fun getGenreByName(genreName: String): DatabaseGenre {
return try {
val foundGenre = GenreEntity.find { Genres.genre eq genreName }.single()
DatabaseGenre(foundGenre.id.value, foundGenre.genre, foundGenre.link)
} catch (e: Exception) {
throw NothingFoundInDatabaseException("no one genre found by '$genreName'")
} catch (e: NoSuchElementException) {
val m = "Duplicates of genre with name '$genreName'"
throw DuplicatedDataInDatabaseException(m)
}
}
In log I see, that sql-query for finding genres is correct, but I receive an exception:
java.util.NoSuchElementException: Collection is empty.
The sql-query, as I said, is correct:
SELECT genres.id, genres.genre, genres.link FROM genres WHERE genres.genre = 'Документальное'
Structure of genres table:
genres
id: int(10)
genre: varchar(100)
link: varchar(100
I tryied, to select all genres, and this query executed almost correctly. So, I decided, to check this query with english word, and this query correctly executed:
SELECT genres.id, genres.genre, genres.link FROM genres WHERE genres.genre = 'simpleGenre'
I have not exceptions with this query.
So, what I've done wrong and how to fix problem with collations?
UPD:
As I said at github (issue), I've tryied this query it mysql cli and I receive correct answer.
Also, I've tryed to decode url params (with java URLDecoder class). It doesn't helps too.
kotlin orm collate kotlin-exposed
kotlin orm collate kotlin-exposed
edited Nov 19 '18 at 7:57
Sergey Grishin
asked Nov 18 '18 at 11:00
Sergey GrishinSergey Grishin
2914
2914
Well, yeah. That's called URL encoding. If it doesn't automatically decode it, you'll need to do so manually.
– Zoe
Nov 18 '18 at 11:20
@Zoe, thanks for your answer. But, why I saw in logs sql-query with cyrillic letters (in "normal" form)? It was without encoded symbols, just normal cyrillic letters. p.s. I'll try your advice and write here results
– Sergey Grishin
Nov 18 '18 at 14:37
@Zoe, I've tryied your advice. It doesn't hepls. I updated my question description with my attempts to fix this problem and linkto github issue, where I wrote that from mysql cli all works fine
– Sergey Grishin
Nov 19 '18 at 7:59
Do you havecharacterEncoding=utf8
parameter in your MySQL connection URL? Likejdbc:mysql://localhost:3306/db?characterEncoding=utf8
. Another helpful parameter isuseUnicode=true
.
– madhead
Nov 21 '18 at 6:31
1
@madhead, fuu** ghm, it's really works. Thank you very mutch. Spent to this a week. Don't know, how to mark this as correct answer
– Sergey Grishin
Nov 22 '18 at 21:35
add a comment |
Well, yeah. That's called URL encoding. If it doesn't automatically decode it, you'll need to do so manually.
– Zoe
Nov 18 '18 at 11:20
@Zoe, thanks for your answer. But, why I saw in logs sql-query with cyrillic letters (in "normal" form)? It was without encoded symbols, just normal cyrillic letters. p.s. I'll try your advice and write here results
– Sergey Grishin
Nov 18 '18 at 14:37
@Zoe, I've tryied your advice. It doesn't hepls. I updated my question description with my attempts to fix this problem and linkto github issue, where I wrote that from mysql cli all works fine
– Sergey Grishin
Nov 19 '18 at 7:59
Do you havecharacterEncoding=utf8
parameter in your MySQL connection URL? Likejdbc:mysql://localhost:3306/db?characterEncoding=utf8
. Another helpful parameter isuseUnicode=true
.
– madhead
Nov 21 '18 at 6:31
1
@madhead, fuu** ghm, it's really works. Thank you very mutch. Spent to this a week. Don't know, how to mark this as correct answer
– Sergey Grishin
Nov 22 '18 at 21:35
Well, yeah. That's called URL encoding. If it doesn't automatically decode it, you'll need to do so manually.
– Zoe
Nov 18 '18 at 11:20
Well, yeah. That's called URL encoding. If it doesn't automatically decode it, you'll need to do so manually.
– Zoe
Nov 18 '18 at 11:20
@Zoe, thanks for your answer. But, why I saw in logs sql-query with cyrillic letters (in "normal" form)? It was without encoded symbols, just normal cyrillic letters. p.s. I'll try your advice and write here results
– Sergey Grishin
Nov 18 '18 at 14:37
@Zoe, thanks for your answer. But, why I saw in logs sql-query with cyrillic letters (in "normal" form)? It was without encoded symbols, just normal cyrillic letters. p.s. I'll try your advice and write here results
– Sergey Grishin
Nov 18 '18 at 14:37
@Zoe, I've tryied your advice. It doesn't hepls. I updated my question description with my attempts to fix this problem and linkto github issue, where I wrote that from mysql cli all works fine
– Sergey Grishin
Nov 19 '18 at 7:59
@Zoe, I've tryied your advice. It doesn't hepls. I updated my question description with my attempts to fix this problem and linkto github issue, where I wrote that from mysql cli all works fine
– Sergey Grishin
Nov 19 '18 at 7:59
Do you have
characterEncoding=utf8
parameter in your MySQL connection URL? Like jdbc:mysql://localhost:3306/db?characterEncoding=utf8
. Another helpful parameter is useUnicode=true
.– madhead
Nov 21 '18 at 6:31
Do you have
characterEncoding=utf8
parameter in your MySQL connection URL? Like jdbc:mysql://localhost:3306/db?characterEncoding=utf8
. Another helpful parameter is useUnicode=true
.– madhead
Nov 21 '18 at 6:31
1
1
@madhead, fuu** ghm, it's really works. Thank you very mutch. Spent to this a week. Don't know, how to mark this as correct answer
– Sergey Grishin
Nov 22 '18 at 21:35
@madhead, fuu** ghm, it's really works. Thank you very mutch. Spent to this a week. Don't know, how to mark this as correct answer
– Sergey Grishin
Nov 22 '18 at 21:35
add a comment |
1 Answer
1
active
oldest
votes
Thanks, @madhead.
I tryied an advance of @madhead, and it works. So, from this time my DB connection URL looks like this:
val connect = Database.connect(
url = "jdbc:mysql://localhost:3306/my_database_name?characterEncoding=utf8&useUnicode=true",
driver = "com.mysql.jdbc.Driver",
user = user_name,
password = password
)
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53360110%2fexposed-kotlin-problem-with-cyrillic-encoding%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks, @madhead.
I tryied an advance of @madhead, and it works. So, from this time my DB connection URL looks like this:
val connect = Database.connect(
url = "jdbc:mysql://localhost:3306/my_database_name?characterEncoding=utf8&useUnicode=true",
driver = "com.mysql.jdbc.Driver",
user = user_name,
password = password
)
add a comment |
Thanks, @madhead.
I tryied an advance of @madhead, and it works. So, from this time my DB connection URL looks like this:
val connect = Database.connect(
url = "jdbc:mysql://localhost:3306/my_database_name?characterEncoding=utf8&useUnicode=true",
driver = "com.mysql.jdbc.Driver",
user = user_name,
password = password
)
add a comment |
Thanks, @madhead.
I tryied an advance of @madhead, and it works. So, from this time my DB connection URL looks like this:
val connect = Database.connect(
url = "jdbc:mysql://localhost:3306/my_database_name?characterEncoding=utf8&useUnicode=true",
driver = "com.mysql.jdbc.Driver",
user = user_name,
password = password
)
Thanks, @madhead.
I tryied an advance of @madhead, and it works. So, from this time my DB connection URL looks like this:
val connect = Database.connect(
url = "jdbc:mysql://localhost:3306/my_database_name?characterEncoding=utf8&useUnicode=true",
driver = "com.mysql.jdbc.Driver",
user = user_name,
password = password
)
answered Nov 22 '18 at 21:51
Sergey GrishinSergey Grishin
2914
2914
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53360110%2fexposed-kotlin-problem-with-cyrillic-encoding%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Well, yeah. That's called URL encoding. If it doesn't automatically decode it, you'll need to do so manually.
– Zoe
Nov 18 '18 at 11:20
@Zoe, thanks for your answer. But, why I saw in logs sql-query with cyrillic letters (in "normal" form)? It was without encoded symbols, just normal cyrillic letters. p.s. I'll try your advice and write here results
– Sergey Grishin
Nov 18 '18 at 14:37
@Zoe, I've tryied your advice. It doesn't hepls. I updated my question description with my attempts to fix this problem and linkto github issue, where I wrote that from mysql cli all works fine
– Sergey Grishin
Nov 19 '18 at 7:59
Do you have
characterEncoding=utf8
parameter in your MySQL connection URL? Likejdbc:mysql://localhost:3306/db?characterEncoding=utf8
. Another helpful parameter isuseUnicode=true
.– madhead
Nov 21 '18 at 6:31
1
@madhead, fuu** ghm, it's really works. Thank you very mutch. Spent to this a week. Don't know, how to mark this as correct answer
– Sergey Grishin
Nov 22 '18 at 21:35