Announcement Announcement Module
Collapse
No announcement yet.
unable to insert arabic data Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • unable to insert arabic data

    Hi All,

    Am trying to do small application with java , spring , hibernate , the problem is that am not able to insert arabic data inspite of my specifications in the spring configuration file
    to use utf-8 as well the database charcterset is utf-8


    here is part of the configuration file
    Code:
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://localhost:3306/general" />
        <property name="username" value="test" />
        <property name="password" value="test" />
        
    </bean>
    
    
    
     <bean id="sessionFactory"
             class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
          <property name="dataSource" ref="dataSource" />
          <property name="mappingResources">
             <list>
                <value>com/account/Account.hbm.xml</value>
                <value>com/account/ShortCode.hbm.xml</value>
             </list>
          </property>
          <property name="hibernateProperties">
             <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
                 <!-- <prop key="hibernate.show_sql">true</prop> -->
    			 <prop key="hibernate.connection.useUnicode">true</prop>
    			 <prop key="hibernate.connection.characterEncoding">UTF-8</prop> 
    			 <prop key="hibernate.connection.charSet">UTF-8</prop> 
             </props>
          </property>
       </bean>

    by the way when i try to insert arabic data , the data will be inserted as question marks in the table of the database.

  • #2
    Hi All,

    Thanks alot , i have fixed the issue ,

    i have added the following into the url

    ?useUnicode=true&amp;characterEncoding=utf-8


    so my code becomes as the following

    Code:
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://localhost:3306/general?useUnicode=true&amp;characterEncoding=utf-8" />
        <property name="username" value="test" />
        <property name="password" value="test" />
        
    </bean>
    
    
    
     <bean id="sessionFactory"
             class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
          <property name="dataSource" ref="dataSource" />
          <property name="mappingResources">
             <list>
                <value>com/account/Account.hbm.xml</value>
                <value>com/account/ShortCode.hbm.xml</value>
             </list>
          </property>
          <property name="hibernateProperties">
             <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
                 <!-- <prop key="hibernate.show_sql">true</prop> -->
    		
             </props>
          </property>
       </bean>
    it is working perfect now

    Comment


    • #3
      Good post

      Wonderful post. Thanks for putting your thoughts so precisely.
      http://www.Start-an-Internet-business.net

      Comment


      • #4
        Why don't you add the encoding filter in your web.xml ?

        Code:
            <filter>
                <filter-name>CharacterEncoding</filter-name>
                <filter-class>
        			org.springframework.web.filter.CharacterEncodingFilter
                </filter-class>
                <init-param>
                    <param-name>encoding</param-name>
                    <param-value>UTF-8</param-value>
                </init-param>
                <init-param>
                    <param-name>forceEncoding</param-name>
                    <param-value>true</param-value>
                </init-param>
            </filter>
        BYE

        Comment

        Working...
        X