Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

JavaWorld Daily Brew

Unable to Insert this Chinese Character Can AnyBody Help



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;
}

}

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 in DataBase