I am getting ?????? instead of Hindi text from MySQL database using JSP.
Here is my JSP code:
<html>
<head>
<title>display data from the table using jsp</title>
</head>
<body>
<h2>Data from the table 'stu_info' of database 'student'</h2>
<%
try {
String connectionURL = "jdbc:mysql://localhost:3306/student";
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL, "root", "root");
statement = connection.createStatement();
String QueryString = "SELECT * from stu_info";
rs = statement.executeQuery(QueryString);
%>
<TABLE cellpadding="15" border="1" style="background-color: #ffffcc;">
<%
while (rs.next()) {
%>
<TR>
<TD><%=rs.getInt(1)%></TD>
<TD><%=rs.getString(2)%></TD>
<TD><%=rs.getString(3)%></TD>
<TD><%=rs.getString(4)%></TD>
</TR>
<% } %>
<%
// close all the connections.
rs.close();
statement.close();
connection.close();
} catch (Exception ex) {
%>
</font>
<font size="+3" color="red"></b>
<%
out.println("Unable to connect to database.");
}
%>
</TABLE><TABLE>
<TR>
<TD><FORM ACTION="welcome_to_database_query.jsp" method="get" >
<button type="submit"><-- back</button></TD>
</TR>
</TABLE>
</font>
</body>
</html>
Three columns of English text are displayed correct. For the Hindi column I have used collation utf-general_ci
, but when I print rs.getString(4)
it gives me ???????
. My browser also supports UTF-8. How is this problem caused and how can I solve it?