on 02-12-2007 1:44 PM
Hi,
I have a problem with encoding of texts loaded from database (slovak, czech).
My application environment first:
MS SQL Server 2000, standard JDBC drivers from Microsoft
DB table encoded in windows-1250
SAP WAS application server on UNIX, file.encoding property = iso-8859-1
Here is part of JSP (using only for tests 😞
<%@ page language="java" contentType="text/html;charset=iso-8859-2"%>
<% request.setCharacterEncoding("iso-8859-2"); %>
...
<%
try {
// ... getting connection
java.sql.Statement stmt = conn.createStatement (
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE );
String q = "SELECT col FROM table where id='1'";
java.sql.ResultSet result = stat.executeQuery(q);
if ( result.next() )
out.write( result.getString(1) );
}
catch ( SQLException sqle )
// ...
%>
Special characters {Slovak, Czech} are corrupted.
In first two lines I've tried utf-8, iso-8859-1, windows-1250 (also with pageEncoding directive) and I've check browser encoding setting in every case.
Then I've tried tens of combination in this way:
out.write( new String (result.getString(1).getBytes("windows-1250"), "iso-8859-1"));
Nothing from this helps.
And now, for me the most interesting part. When I change line with statement creation from:
stmt = conn.createStatement ( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
to:
stmt = conn.createStatement ( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
diacritic works... (for every setting {iso-8859-2, utf-8, windows-1250} )
I've tried to do these changes in environment configuration::
1. SAP WAS on UNIX + Oracle 10g
2. SAP WAS on Windows + MS SQL 2000
3. standalone java application + MS SQL 2000
All 3 works fine with ResultSet.CONCUR_UPDATABLE...
Can you give me advice, how to solve this problem? Thanks for any answer.
Regards,
Juraj
Hi Juraj,
If the column containing the texts is supporting unicode (with nVarchar, nChar,etc), don't bother to set the charset;
otherwise
You can try to put "charset=iso-8859-1;" in your JDBC URL if the "iso-8859-1" is the corresponding charset for slovak,czech.
For instance,
jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=XXX;SelectMethod=cursor;charset=iso-8859-1
By the way, you can output the texts after they are retrieved from database to see if the problem is related to JDBC or JSP.
for instance,
Put the following line to the if block,
System.out.println( result.getString(1));
if ( result.next() ){
String stringFromDB = result.getString(1);
System.out.println(StringFromDB);
out.write( [stringFromDB );
}
Dennis
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Dennis,
Thanks a lot for your answer. I've changed charset for JDBC connection by your suggestions, but still no success. (also i've tried another charsets)
For slovak or czech characters I need one of these charsets: ISO-8859-2, windows-1250, UTF-8. ISO-8859-1 is file encoding property of SAP WAS JVM.
I think problem is in JSP and only when Statement was created with property ResultSet.CONCUR_UPDATABLE (I think when the ResultSet is updatable, is encoded with ISO-8859-1 (as default for my UNIX WAS) and special characters are destroyed -- maybe this is stupid, but my only explanation).
Console output and JSP output on Windows WAS are OK in any case. (And output on UNIX WAS with Oracle 10g, too!!!)
Regards,
Juraj
User | Count |
---|---|
95 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.