[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Jsp - Jconnector - MySql : Problem with danish characters

Posted on 2003-03-20
6
Medium Priority
?
343 Views
Last Modified: 2008-02-01
What a mess!

I am building a web application using JSP connected to a MySQL Database via Jconnector.

My problem with the characters are threefold:

At the MySQL prompt I can use the danish letters "æ" and "å", but not "ø" - it is display like an "o".

When I write (for testing purposes) to the J2EE-Console the "æ" becomes a "'", the "å" is a strange looking spot and the "ø" is again "o".

When I write the characters to a JSP page the browser displays both "æ" and "å" as "?" and again the "ø" as "o".

I need the charaters to be THE SAME AT ALL THREE LEVELS.

Any experts know how?
0
Comment
Question by:NicolaiKrog
  • 3
  • 2
6 Comments
 

Author Comment

by:NicolaiKrog
ID: 8177670
OH NO!!!

I can now see that the danish characters are not displayed correctly either here at EE !!!!

AAAARRRRRRRRRRRGGGGGGGGGGGGHHHHHHH! Tough to be a Dane!!!!

Still need help!
0
 

Author Comment

by:NicolaiKrog
ID: 8177682
Please ignore the letter-examples, I did not type "f", "e" and "x". I typed the the danish characters, that apparently does not work here either.  
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 8178326
I would suggest you try use utf-8 encoding for web:

1. in every jsp page, include this
<%@ page contentType="text/html; charset=UTF-8" %>
<%request.setCharacterEncoding( "UTF-8" );%>

2. in every html page you need this line in your html <head>:
<META HTTP-EQUIV="CONTENT-TYPE"CONTENT="TEXT/HTML;CHARSET=UTF-8">

3. when store into database always use preparedStatement
PrepareStatement ps = conn.prepareStatement( "insert into table1( field1 ) value ( ? )" );
ps.setString( 1, data );
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 14

Accepted Solution

by:
kennethxu earned 1500 total points
ID: 8178493
try out this example:

<%@ page import="java.sql.*" %>
<%@ page contentType="text/html; charset=UTF-8" %>
<%request.setCharacterEncoding( "UTF-8" );%>

<html>
<head>
<META HTTP-EQUIV="CONTENT-TYPE"CONTENT="TEXT/HTML;CHARSET=UTF-8">
</head>
<body>
<form method="post">
<input type="text" name="data">
<input type="submit">
</form>
<% String data = request.getParameter( "data" ); %>
<p>Data submitted: <%=data%>
<p>Data from database:
<%
  // ******* create your database connection here
  Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
  Connection conn = DriverManager.getConnection( "jdbc:odbc:test", "admin", "" );
  if( data != null ) {
     PreparedStatement ps = conn.prepareStatement( "insert into table1( field1 ) values ( ? )" );
     ps.setString( 1, data );
     ps.executeUpdate();
    ps.close();
  }
  Statement stat = conn.createStatement();
  ResultSet rs = stat.executeQuery( "select field1 from table1" );
  while( rs.next() ) {
    String fromDB = rs.getString( 1 );
%>
<br><%=fromDB%>
<%}%>
     
</body>
</html>
0
 

Author Comment

by:NicolaiKrog
ID: 8191848
Thanks for the work Kenneth!

I have now solved the problem, - a combination of your suggestions, but most importantly I have realized that when new data are inserted into the database, it should always be done via JSP if you want to retreive them via JSP!

Ie. data inserted from the prompt != data retreived from jsp!

But thanks for your time , - you get the points!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Custom Android App Development is the need of an hour for several businesses. If you go through the right firm for Android Application Development, it can make a huge difference to the ways in which customers interact with your business.
Virtualization software lets you run different versions of Windows, Ubuntu Linux and other versions of Linux all at the same time, rather than running each one directly from your computer's hard drive.
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
This video tutorial shows you the steps to go through to set up what I believe to be the best email app on the android platform to read Exchange mail.  Get the app on your phone: The first step is to make sure you have the Samsung Email app on your …
Suggested Courses

590 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question