| Author |
Unable to Insert these Chinese Character
|
Imtiaz Ahmed
Greenhorn
Joined: Dec 01, 2008
Posts: 12
|
|
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 racle:thin:@machine_name:1521:database_name", "scott", "tiger"); */ static String userid="XGLIVE", password = "AIOICHLIVE"; static String url = "jdbc racle: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; } }
|
 |
swapna hyderabad
Greenhorn
Joined: Nov 20, 2008
Posts: 20
|
|
Hi,, what is the data type of the cloumn you are trying to insert??
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
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.
|
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
|
 |
Imtiaz Ahmed
Greenhorn
Joined: Dec 01, 2008
Posts: 12
|
|
|
Column is VARCHAR2(100)
|
 |
Imtiaz Ahmed
Greenhorn
Joined: Dec 01, 2008
Posts: 12
|
|
For all chinese Characters its working fine U can test as well Not for this Character I dont know Why
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
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
Joined: Dec 01, 2008
Posts: 12
|
|
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
Joined: Dec 01, 2008
Posts: 12
|
|
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
Joined: Apr 14, 2004
Posts: 10336
|
|
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
Joined: Dec 01, 2008
Posts: 12
|
|
Just sending query String InsertStatement="insert into chinesechar values('塚')"; to execute Means i am hardcoding that value
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
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
Joined: Dec 01, 2008
Posts: 12
|
|
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
Joined: Dec 01, 2008
Posts: 12
|
|
|
its Oracle 9.2.0.5
|
 |
Imtiaz Ahmed
Greenhorn
Joined: Dec 01, 2008
Posts: 12
|
|
oracle.jdbc.driver.OracleDriver -- driver type--thin
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
|
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
Joined: Dec 01, 2008
Posts: 12
|
|
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
Joined: Apr 14, 2004
Posts: 10336
|
|
|
Oracle drivers are backward compatable I think - the newer thin drivers should connect fine to an older database. Try the latest one.
|
 |
 |
|
|
subject: Unable to Insert these Chinese Character
|
|
|