Solved

Arabic JDBC

Posted on 2009-05-11
41
372 Views
Last Modified: 2012-06-22
Hi  experts,

I need to pass arabic string in sql query. i have already did but this is the output query :

sellect FULL_NAME,MOBILE,FAX,BUSINESS_TEL,DEPARTMENT,LDAP_ID from STAFF_DIRECTORY_VW Where lower(FIRST_NAME) LIKE lower ('%شماء%')

I tried  to do this:

last_Name = request.getParameter("EMP_LASTNAME");
byte [] by1252 = last_Name.getBytes("Cp1252");
 last_Name = new String(by1252, "Cp1256");

how should i set the proper unicode? i compiled java class in my machine then copied to the server ? should i compile it in the server?

ur help plz, the deadline is tomorrow :(  
0
Comment
Question by:Web_Admin
  • 20
  • 11
  • 9
  • +1
41 Comments
 
LVL 8

Expert Comment

by:Haris V
ID: 24361491
please try this,

try writing a program that retrieves the data from the DB, set the jvm -Dfile.encoding value to the proper encoding. This will check if the value you stored in the database is correct.


or

please check this link,

1. http://oracle.cs.uoi.gr/enterprise_server/java.815/a64685/advanc1.htm
0
 

Author Comment

by:Web_Admin
ID: 24361532
sirah,

i was able to select arabic records from the databse and display it in the browser, i need to pass arabic string in the where condition

Thanks for ur replay, i will check the links
0
 
LVL 92

Expert Comment

by:objects
ID: 24361540
you don't need to compile it in the server?

Is Cp1252 the encoding used by your form?

0
 

Author Comment

by:Web_Admin
ID: 24361568
objects
sorry didn't get u, This is the system encoding:ISO8859-1
0
 
LVL 92

Expert Comment

by:objects
ID: 24361598
> last_Name = request.getParameter("EMP_LASTNAME");

are you getting the correct value from the request for last_Name?

0
 

Author Comment

by:Web_Admin
ID: 24361624
objects:

yes and i printed in right encoding in the browser before pass it to the jdbc method?
0
 
LVL 92

Expert Comment

by:objects
ID: 24361636
no i meant once it gets to the server (it gets encoded in the request)
check it server side
0
 

Author Comment

by:Web_Admin
ID: 24361673
not it does print it in the right encoing:

This is the out put:

string last name: شماء

so ? :)
0
 

Author Comment

by:Web_Admin
ID: 24361682
This is what i have print, if u got u right:

System.out.println("111111111111111111string last name: "+last_Name);

output: string last name: شماء
0
 

Author Comment

by:Web_Admin
ID: 24361869
how i can check the jsp version ?
0
 
LVL 92

Expert Comment

by:objects
ID: 24361878
the jsp versio is not an issue, you need to check the encoding used by your jsp container.
0
 

Author Comment

by:Web_Admin
ID: 24361918
how about parse the request to bytes then converted to UTF-8 pass it to the query ?
0
 

Author Comment

by:Web_Admin
ID: 24361933
I printed encoding
encoding request: null
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24361977
>>sorry didn't get u, This is the system encoding:ISO8859-1

What do you mean by 'system'? If you mean the db, it can't store Arabic in that encoding except by escapement.

Question, can you successfully query the db *outside Java* and get back an Arabic string?
0
 
LVL 92

Expert Comment

by:objects
ID: 24361987
specify the appropriate encoding for your container to use

0
 

Author Comment

by:Web_Admin
ID: 24361997
how i can change file encoding of the jvm?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24361999
If you have mixed Latin and Arabic data, you should set your db encoding to UTF8
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24362008
>>how i can change file encoding of the jvm?

It's nothing to do with the jvm
0
 
LVL 92

Expert Comment

by:objects
ID: 24362011
> how i can change file encoding of the jvm?

thats not what you need to change, you need to change the encoding used by the container that is running your jsp to UTF-8 (or whatever is required)

0
 

Author Comment

by:Web_Admin
ID: 24362040
CEHJ:

sorry didn't see ur comment
Yeah i can select "select * from db" retrieve arabic records and display them in the browser successfully
but the problem when i pass arabic string in the where condition, it is not encoing well:

sellect FULL_NAME,MOBILE,FAX,BUSINESS_TEL,DEPARTMENT,LDAP_ID from STAFF_DIRECTORY_VW Where lower(FIRST_NAME) LIKE lower ('%شماء%')

>>What do you mean by 'system'?
i meant System.getProperty("file.encoding"));
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 92

Expert Comment

by:objects
ID: 24362052
your database is fine, you need to check the configuration of your container.
What container are you using?

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24362095
If you're entering the query like that, you probably would be better with:
select FULL_NAME,MOBILE,FAX,BUSINESS_TEL,DEPARTMENT,LDAP_ID from STAFF_DIRECTORY_VW 

Where lower(FIRST_NAME) LIKE lower ('%\u0634\u0645\u0627\u0621%') 

Open in new window

0
 
LVL 92

Expert Comment

by:objects
ID: 24362116
And use a PreparedStatement to handle the encoding of the string in your sql, a lot simpler and more efficient

0
 

Author Comment

by:Web_Admin
ID: 24362154
CEHJ
>>%\u0634\u0645\u0627\u0621%
what is this? didn't get? how should i convert my string to this encoding?

objects:
The running query is generated according to what user types in the search form, see below code
    String query = "Select " +

            "FULL_NAME," +

             "MOBILE," +

             "FAX," +

             "BUSINESS_TEL," +

             "DEPARTMENT," +

             "LDAP_ID " +

             "from STAFF_DIRECTORY_VW Where ";

    

  System.out.println("Query in basic search: "+query);

    

    StringTokenizer token = new StringTokenizer(keyword, " ");

    int i = 0;

    while (token.hasMoreTokens()) {
 

                String tk = token.nextToken();
 

                if (i == 0) {

                     query += "(lower(SEARCH_FIELD) LIKE lower ('%" + tk + "%')) " ;

                            
 

                } else {
 

                      query += "AND ( lower(SEARCH_FIELD) LIKE lower ('%" + tk + "%')) " ;

                       

                }
 
 

                i++;
 

            }

Open in new window

0
 

Author Comment

by:Web_Admin
ID: 24362157
jsp container is tomcat
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24362185
If your query is coming dynamically, you need to set everything up to use UTF-8 throughout
0
 

Author Comment

by:Web_Admin
ID: 24362203
CEHJ

I have two arabic fileds in the database that i should include in the query and the rest r english fileds
how should i set encoding to UTF-8? this is the big question =D
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 250 total points
ID: 24362302
Have a look at the following

http://cagan327.blogspot.com/2006/05/utf-8-encoding-fix-tomcat-jsp-etc.html

I would ignore the Filter configuration at first. Just ensure that file.encoding is set to UTF-8 in the jvm options in Tomcat
0
 

Author Comment

by:Web_Admin
ID: 24362375
I have did deploy the following page to test first line:

<%@ page language="java" pageEncoding="utf-8" contentType="text/html;charset=utf-8"%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h2>Hello World!</h2>
    </body>
</html>

This exception is thrown:
 Internal error: servlet service function had thrown ServletException (uri=/cp/jsp/search_directory/test.jsp): org.apache.jasper.compiler.ParseException: /opt/luminis/webapps/luminis/jsp/search_directory/test.jsp(0,0) Page directive: Invalid attribute, pageEncoding, stack: org.apache.jasper.compiler.ParseException: /opt/luminis/webapps/luminis/jsp/search_directory/test.jsp(0,0) Page directive: Invalid attribute, pageEncoding

i think my jsp version is not supporing pageEncoding attribute ?
0
 
LVL 92

Expert Comment

by:objects
ID: 24362606
what version of tomcat?

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24362681
You need JSP version >= 1.2 support
0
 

Author Comment

by:Web_Admin
ID: 24363035
sorry, i thought it was tomcat,
it is Sun ONE Web Server
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24363136
Make sure you have JSP >= 1.2
0
 

Author Comment

by:Web_Admin
ID: 24363305
This is our server:

Sun ONE Web Server 6.1 includes a Java" 2 Platform, Enterprise Edition (J2EE")-compliant implementation of the Java" Servlet 2.3 and JavaServer Pages" (JSP") 1.2 specifications.
 and JDK is 1.3
0
 
LVL 92

Expert Comment

by:objects
ID: 24363326
I'd be thinking about upgrading your jdk :)
0
 

Author Comment

by:Web_Admin
ID: 24363379

if it is up to me, i would upgrade it immediatley.
The "fu** portal" is running under 1.3 , i hope sunguard do jdk upgrade in next version
so we r done from this nightmare :(
0
 

Author Comment

by:Web_Admin
ID: 24363441
I have tried this;

request.setCharacterEncoding("UTF-8");

Method setCharacterEncoding(java.lang.String) not found in interface javax.servlet.http.HttpServletRequest.

OMG
when we open door, jdk close it :(
0
 

Author Comment

by:Web_Admin
ID: 24381830
0
 
LVL 92

Assisted Solution

by:objects
objects earned 250 total points
ID: 24381850
basically says what I've mentioned a few times in that you need to setup your container and application to use UTF8 throughout.
I'd give you more specific help but we don't use Sun One so not sure on configuring it. As far as configuring your application setting up a character encoding filter is a good start.

use firebug to have a look at the request and responses being sent to get a better idea about what point in the chain things are getting broken.

0
 

Author Comment

by:Web_Admin
ID: 24381955

Thanks objects

Actually my boss doesn't want to do serious changes on the server for such thing, so am going to re-develop application in asp ( first time to develop by asp, hope is it easy *-*).

Thanks again
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24383704
:-)
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
endX challenge 2 50
where is session ID cache stored 1 40
Modeling a class in java 5 34
Java Loop 6 25
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now