views:

72

answers:

2

Well, the subject says it all but I will explain a little further.

I have a database in MS SQL server 2005 that contains greek text. I have created a servlet that connects to that database using net.sourceforge.jtds.jdbc.Driver and receive some data with the following commands:

Connection con = DriverManager.getConnection(connectionUrl);
Statement sta = con.createStatement(); 
ResultSet res = sta.executeQuery("SELECT * FROM data");

After that, I want to use output.println to display the data to the page. The result is that greek characters are displayed as question marks (?). I tried changing the encoding charset of the browser, but no luck, so the problem must be to the page. I also tried displaying

new String( res.getBytes("text"), "ISO-8859-7");

instead of res.getString("text"), with different encodings (UTF-8, UTF-16), but still no luck !

What can I do to see the greek characters ???

TIA !

+1  A: 

The problem may be at a number of locations. Check them all:

  • the database encoding
  • the connection encoding
  • the response encoding (response.setCharacterEncoding("utf-8"))
Bozho
The problem was with the response encoding. Adding the line response.setContentType ("text/html;charset=utf-8"); solved the problem !
Serafeim
+1  A: 

You need to set the response encoding to UTF-8. Since you normally use JSP for displaying data, you can do this by placing the following line at the top of the JSP page:

<%@ page pageEncoding="UTF-8" %>

Also see this article for more background information and all the other aspects you'll need to take into account as well for a Java EE webapplication.

BalusC
I was using servlets instead of JSP, however the article about unicode was great !
Serafeim