Imtiaz Ahmed

Greenhorn
+ Follow
since Dec 01, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Imtiaz Ahmed

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
oracle.jdbc.driver.OracleDriver -- driver
type--thin
what I think from
stmt.executeUpdate(InsertStatement);---->Database
its not going properly
My doubts will be
1.May be problem with Driver
Just sending query
String InsertStatement="insert into chinesechar values('塚')";
to execute
Means i am hardcoding that value
As You can see that in the below code there are two characters
1.'塚'
2.'天'

I can able to insert 2 but not 1
when i am insert by sqlplus its inserting i mean the 2 character
where as when i use JDBC its not inserting instead it gives '?'

when i quered
Select value from SYS.NLS_DATABASE_PARAMETERS where PARAMETER = 'NLS_CHARACTERSET'
it gave me ZHS16CGB231280


Can anyone help me in inserting this character properly into database






package org.com;

import java.io.UnsupportedEncodingException;
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 str="塚";
//String str="天";

String InsertStatement="";
/*try{
String s = new String(str.getBytes(), "GB2312");
InsertStatement="insert into chinesechar values('"+s+"')";
} catch (UnsupportedEncodingException e) {
// just ignore, if the named encoding is not supported.
}*/

InsertStatement="insert into chinesechar values('"+str+"')";
//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;
}


}
The Implementation for Connection Interface will be there in related Jars
means for Example if you are using database is Oracle 9i then it will be ojdbc14.jar
You can see in that jar for Implementation class
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?
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
For all chinese Characters its working fine U can test as well
Not for this Character I dont know Why
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;
}


}