[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 388
  • Last Modified:

Arabic JDBC

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
Web_Admin
Asked:
Web_Admin
  • 20
  • 11
  • 9
  • +1
2 Solutions
 
Haris VCommented:
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
 
Web_AdminAuthor Commented:
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
 
objectsCommented:
you don't need to compile it in the server?

Is Cp1252 the encoding used by your form?

0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
Web_AdminAuthor Commented:
objects
sorry didn't get u, This is the system encoding:ISO8859-1
0
 
objectsCommented:
> last_Name = request.getParameter("EMP_LASTNAME");

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

0
 
Web_AdminAuthor Commented:
objects:

yes and i printed in right encoding in the browser before pass it to the jdbc method?
0
 
objectsCommented:
no i meant once it gets to the server (it gets encoded in the request)
check it server side
0
 
Web_AdminAuthor Commented:
not it does print it in the right encoing:

This is the out put:

string last name: شماء

so ? :)
0
 
Web_AdminAuthor Commented:
This is what i have print, if u got u right:

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

output: string last name: شماء
0
 
Web_AdminAuthor Commented:
how i can check the jsp version ?
0
 
objectsCommented:
the jsp versio is not an issue, you need to check the encoding used by your jsp container.
0
 
Web_AdminAuthor Commented:
how about parse the request to bytes then converted to UTF-8 pass it to the query ?
0
 
Web_AdminAuthor Commented:
I printed encoding
encoding request: null
0
 
CEHJCommented:
>>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
 
objectsCommented:
specify the appropriate encoding for your container to use

0
 
Web_AdminAuthor Commented:
how i can change file encoding of the jvm?
0
 
CEHJCommented:
If you have mixed Latin and Arabic data, you should set your db encoding to UTF8
0
 
CEHJCommented:
>>how i can change file encoding of the jvm?

It's nothing to do with the jvm
0
 
objectsCommented:
> 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
 
Web_AdminAuthor Commented:
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
 
objectsCommented:
your database is fine, you need to check the configuration of your container.
What container are you using?

0
 
CEHJCommented:
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
 
objectsCommented:
And use a PreparedStatement to handle the encoding of the string in your sql, a lot simpler and more efficient

0
 
Web_AdminAuthor Commented:
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
 
Web_AdminAuthor Commented:
jsp container is tomcat
0
 
CEHJCommented:
If your query is coming dynamically, you need to set everything up to use UTF-8 throughout
0
 
Web_AdminAuthor Commented:
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
 
CEHJCommented:
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
 
Web_AdminAuthor Commented:
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
 
objectsCommented:
what version of tomcat?

0
 
CEHJCommented:
You need JSP version >= 1.2 support
0
 
Web_AdminAuthor Commented:
sorry, i thought it was tomcat,
it is Sun ONE Web Server
0
 
CEHJCommented:
Make sure you have JSP >= 1.2
0
 
Web_AdminAuthor Commented:
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
 
objectsCommented:
I'd be thinking about upgrading your jdk :)
0
 
Web_AdminAuthor Commented:

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
 
Web_AdminAuthor Commented:
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
 
Web_AdminAuthor Commented:
0
 
objectsCommented:
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
 
Web_AdminAuthor Commented:

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
 
CEHJCommented:
:-)
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 20
  • 11
  • 9
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now