You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "pmirco@inwind.it" <pm...@inwind.it> on 2003/01/02 12:54:39 UTC

jdbc, mysql and character encoding

I've my jsp, where I simply want to fill a table with some "italian" characters:

<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection ("jdbc:mysql://localhost:3306/jdbctest?useUnicode=true&characterEncoding=ISO-8859-1", "usrjdbc", "pwd");
Statement stmt = conn.createStatement();
stmt.executeUpdate("INSERT INTO table (text) VALUES ('àèìùò')");
ResultSet rs = stmt.executeQuery("SELECT * FROM table");
while (rs.next()) {
   int id = rs.getInt("id");
   String text = rs.getString("text");
   out.print("row#" + rs.getRow() + ": id=" + id + ", text=" + text);
   out.println("<br>");
}
stmt.close();
conn.close();
%>

Everything works fine, and when I print the content of the db with the getString mehotd, I see my characters.
The problem is that when I go to the MySQL prompt, I can see strange characters isntead of the ones I tried to write.

MySQL uses the default ISO-8859-1 encoding, and since I'm telling to the JDBC driver to use ISO-8859-1, I can't explain what's wrong


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: jdbc, mysql and character encoding

Posted by Joel Rees <jo...@alpsgiken.gr.jp>.
> It doesnt really matter, as long as you get the desired result in your 
> application...

Well, actually, MSW2k supposedly can have optional languages/encodings loaded,
chosen on a per-user basis, and the console supposedly does display the
language and encoding the user is set up for. I'd assume MSWxp does as
well, but maybe not all versions. Mac OS X handles setting the language
per-user, but the shell does not seem to handle multi-byte encodings yet.



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: jdbc, mysql and character encoding

Posted by Anastasios Angelidis <vo...@videotron.ca>.
Well I know for a fact that if you are using windows, the console window 
canot display extended characters. Only the standard ASCII chars...

It doesnt really matter, as long as you get the desired result in your 
application...

All characters in the end are bytes, a byte is a byte it all depends how 
each application interprets the bytes and displays them. So if the the 
console application uses the standard printf functions etc... you will 
see the weird characters ;)

pmirco@inwind.it wrote:

>I've my jsp, where I simply want to fill a table with some "italian" characters:
>
><%
>Class.forName("com.mysql.jdbc.Driver").newInstance();
>Connection conn = DriverManager.getConnection ("jdbc:mysql://localhost:3306/jdbctest?useUnicode=true&characterEncoding=ISO-8859-1", "usrjdbc", "pwd");
>Statement stmt = conn.createStatement();
>stmt.executeUpdate("INSERT INTO table (text) VALUES ('àèìùò')");
>ResultSet rs = stmt.executeQuery("SELECT * FROM table");
>while (rs.next()) {
>   int id = rs.getInt("id");
>   String text = rs.getString("text");
>   out.print("row#" + rs.getRow() + ": id=" + id + ", text=" + text);
>   out.println("<br>");
>}
>stmt.close();
>conn.close();
>%>
>
>Everything works fine, and when I print the content of the db with the getString mehotd, I see my characters.
>The problem is that when I go to the MySQL prompt, I can see strange characters isntead of the ones I tried to write.
>
>MySQL uses the default ISO-8859-1 encoding, and since I'm telling to the JDBC driver to use ISO-8859-1, I can't explain what's wrong
>
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>
>  
>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>