• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Unable to Insert these Chinese Character

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to Insert this character into Database but its going as '?' instead of '塚'

Can any one tell me why it is happening like that

The code for that is given below




package org.com;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class InsertIntoDB {

/**
* @param args
*/
/*
* con=DriverManager.getConnection(
"jdbc:oracle:thin:@machine_name:1521:database_name",
"scott",
"tiger");
*/
static String userid="XGLIVE", password = "AIOICHLIVE";
static String url = "jdbc:oracle:thin:@192.168.1.101:1521:AIOITRG";// String url = "jdbc:mySubprotocol:myDataSource"; ?
static Statement stmt;
static Connection con;

public static void main(String[] args) {
// TODO Auto-generated method stub


System.out.println("Enter the value want to Insert");
/*BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String value = null;

try {
value = br.readLine();
} catch (IOException ioe) {
System.out.println("IO error trying to read your value");
System.exit(1);
} */

con = getConnection();
String InsertStatement="insert into chinesechar values('塚')";

try {
stmt = con.createStatement();
stmt.executeUpdate(InsertStatement);

stmt.close();
con.close();
System.out.println("Your Value is Inserted");
} catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
}




}
public static Connection getConnection()
{

try {
Class.forName("oracle.jdbc.driver.OracleDriver");

} catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}

try {
con = DriverManager.getConnection(url,
userid, password);

} catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
}

return con;
}


}
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,,
what is the data type of the cloumn you are trying to insert??
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I am trying to Insert this character into Database but its going as '?' instead of '塚'


Two possible reasons spring to mind: 1) your database does not support unicode, or 2) the client you view your data through does not have an encoding to display chinese characters.
 
Imtiaz Ahmed
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Column is VARCHAR2(100)
 
Imtiaz Ahmed
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For all chinese Characters its working fine U can test as well
Not for this Character I dont know Why
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Imtiaz Ahmed:
Column is VARCHAR2(100)



This data type will support Chinese characters fine, just so long as your database has been created to support unicode.
 
Imtiaz Ahmed
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I am directly running this
insert into chinesechar values('塚') statement in toad its inserting the value
When I am inserting it by Java code means using JDBC unable to Insert
the value
 
Imtiaz Ahmed
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When using JDBC I can't able to insert this value where as when I am inserting by Toad it shows in DB.What do you think Database doesn't support unicode in this case?
I think if it doesnt support meansit should not insert the value?
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Imtiaz Ahmed:
When using JDBC I can't able to insert this value where as when I am inserting by Toad it shows in DB.What do you think Database doesn't support unicode in this case?
I think if it doesnt support meansit should not insert the value?



Ok, so we probably know that your database support unicode (a better way to know would be to check your database configuration). And we know that Java does too. So the only place left to check is how you read the Chinese character into your application. How do you do that?
 
Imtiaz Ahmed
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just sending query
String InsertStatement="insert into chinesechar values('塚')";
to execute
Means i am hardcoding that value
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, which version of Oracle are you using? And which version/type of JDBC driver are you using?
[ December 02, 2008: Message edited by: Paul Sturrock ]
 
Imtiaz Ahmed
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what I think from
stmt.executeUpdate(InsertStatement);---->Database
its not going properly
My doubts will be
1.May be problem with Driver
 
Imtiaz Ahmed
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
its Oracle 9.2.0.5
 
Imtiaz Ahmed
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oracle.jdbc.driver.OracleDriver -- driver
type--thin
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok - all I can suggest is to try the latest driver. The version of Oracle you have is fairly old (and no longer supported). Not sure if that might be an issue; you might want to move onto a supported version as well.
 
Imtiaz Ahmed
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank You very much for your Support and having that much patiency to read my every message

But this is my last message for this Issue

Can you tell me is new driver can support old databases
If so which driver is appropriate to my Database
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oracle drivers are backward compatable I think - the newer thin drivers should connect fine to an older database. Try the latest one.
 
reply
    Bookmark Topic Watch Topic
  • New Topic