mercredi 22 juin 2011

the Solution of select and insert on JSP / mysql (English virsion)

i suffered with this big problem , i google it  for many days , ther is no solution 

blieve mei found none solution  .

and i tryied find a solution  myself , and i did it finaly

so here is the solution and i have tested it for month ,plus i created a web site with this library and t work perfectly ,

the library have 2 functions 

enco(String arabic ) , and deco(String arabic)

the booth return  String

enco when you save a value into database , and decod for geting a value from database  , 

it's works with any database provider  , mysql , oracle ....

notice :

you need to writ this 2 lines on the first of every page you use on it the none latine in our case the arabic 

<%request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");%>

how to use this library:

1:go to library fil into you application directory and add our library

2: then on you jsp/servlet page  import the library like this
<%@page import="imad.*" %>

3: the when you neead to insert a arabic line use the library like this 
String art=imadboy.enco(art2);
int t=Service.update("insert into table values( '"+art+"');  

art2 it's your arabic string 
and it's done :) the arabic string saved succesfuly 

4 : when u need to select from database use this 
RseultSet rs=Service.select("select from table where name='arabic'");
if(rs.next()){
String article = imadboy.deco(rs.getString(2));
}


5 : no more , this is how it's work :) now time to download the library and an exempl


1 commentaire:

  1. Well u don't need to encode and decode if u initialize your connection like this:
    DriverManager.getConnection("jdbc:mysql://dblink/dbname?useUnicode=true&characterEncoding=utf-8", "user", "pass");

    RépondreSupprimer