开发者

Reading Greek text from jdbc / SQL Server 2005 and displaying it with a servlet

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-1开发者_如何转开发6), but still no luck!

What can I do to see the greek characters?


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"))


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜