Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JSP not showing UTF-8 data from MySQL

843838Mar 30 2006 — edited Dec 16 2007
Hi all,
I have a mysql (5.0.19) database containing UTF-8 encoded data (greek).
I'm trying to show this data through Tomcat 5.5.16 and JSP.
I start my page like this:
<%@ page import = "java.sql.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<%
		// Connect to the database
		Class.forName("com.mysql.jdbc.Driver").newInstance();
		String dbURL = "jdbc:mysql://localhost:3306/mydb?useUnicode=true&characterEncoding=utf-8";
		Connection connection = DriverManager.getConnection( dbURL, "myuser", "mypass" );
		Statement statement = connection.createStatement();
	%>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
If I show the page like this the data is ok, but I need to set the encoding by hand in my browser. This way I see my strings correctly, in greek
If I add
<%@ page language = "java" contentType = "text/html; charset=UTF-8" pageEncoding = "UTF-8"%>
at the top of my page, it show as UTF-8 but my data is not displayed correctly. Any ideas what's the problem?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 13 2008
Added on Mar 30 2006
3 comments
212 views