aspose file tools*
The moose likes Oracle/OAS and the fly likes Problem of using setCharacterStream method to insert varchar2 data in oracle816 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Products » Oracle/OAS
Bookmark "Problem of using setCharacterStream method to insert varchar2 data in oracle816" Watch "Problem of using setCharacterStream method to insert varchar2 data in oracle816" New topic
Author

Problem of using setCharacterStream method to insert varchar2 data in oracle816

Jason Wu
Greenhorn

Joined: Sep 03, 2002
Posts: 13
hi,i have a problem in inserting into table in oracle816.My OS platform is win2000 Simplified.I want to insert some chinese simplified data in Oracle.Although data are inserted,but the result data is not in proper order.For example,the sql "insert into table(A,B,C) values ('i','love','u')" can be executed successfully.But the result data in table is
A B C
---------
u i love
the result order is wrong.
Can anyone give some ideas?Here are my code,you can try it.Thanks.
import java.io.*;
import java.sql.*;
import java.util.*;
import oracle.sql.*;
public class testDB {
public static void main(String[] args) {
Connection conn = null;
int maxRowSize = 1000;
try{
long before = System.currentTimeMillis();
Class.forName("oracle.jdbc.driver.OracleDriver");
//conn = DriverManager.getConnection("jdbc racle ci8:@sem","bdx","bdx");
conn = DriverManager.getConnection("jdbc racle:thin:@why:1521 radb","ecomm","ecomm");
//createTable(conn); // this is to create table
case1(conn);
//dropTable(conn);
}catch(Exception e){
System.out.println("the exception="+e.getMessage());
e.printStackTrace();
} finally {
try {
conn.close();
} catch (Exception e) {}
}
}
private static void case1(Connection dbConnection) {
int resultCount = -2;
try {
String c2000 = "", c4000 = "", c4001 = "";
for(int i = 0; i < 300; i++) {
c2000 += "你";
}
for(int i = 0; i < 1000; i++) {
c4000 += "我";
c4001 += "爱";
}
//char[] cr = new char[c4001.length()];
//c4001.getChars(0, c4001.length(), cr, 0);
Reader sr2000 = new StringReader(c2000);
Reader sr4000 = new StringReader(c4000.toString());
Reader sr4001 = new StringReader(c4001.toString());
//Reader sr4001 = new CharArrayReader(cr);
System.out.println("c2000 length:" + c2000.length());
System.out.println("c4000 length:" + c4000.length());
System.out.println("c4001 length:" + c4001.length());
String queryStr = "insert into test(c4000, c4001, c2000) values(?,?,?)";
PreparedStatement pst = dbConnection.prepareStatement(queryStr);
pst.setCharacterStream(1, sr4000, c4000.length());
//pst.setString(2, "abcd");
pst.setCharacterStream(2, sr4001, c4001.length());
pst.setCharacterStream(3, sr2000, c2000.length());
/*
pst.setString(1,c4000);
pst.setString(2,c4001);
pst.setString(3,c2000);
*/
pst.executeUpdate();
pst.close();
} catch(Exception se) {
System.out.println("Unable to update" + se);
}
}
private static void createTable(Connection dbConnection) {
int resultCount = -2;
try {
String queryStr = "create table test(c2000 varchar2(2000), c4000 varchar2(4000), c4001 varchar2(4000))";
PreparedStatement pst = dbConnection.prepareStatement(queryStr);
resultCount = pst.executeUpdate();
pst.close();
} catch(Exception se) {
System.out.println("Unable to create" + se);
}
}
private static void dropTable(Connection dbConnection) {
int resultCount = -2;
try {
String queryStr = "drop table test";
PreparedStatement pst = dbConnection.prepareStatement(queryStr);
resultCount = pst.executeUpdate();
pst.close();
} catch(Exception se) {
System.out.println("Unable to drop" + se);
}
}
private static Timestamp toTimestamp(long time){
return new Timestamp(time);
}
private static String[] toArray(ArrayList arr){
String[] strArr = new String[arr.size()];
for (int i=0;i strArr[i] = (String)arr.get(i);
}
return strArr;
}
}
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

String queryStr = "insert into test(c4000, c4001, c2000) values(?,?,?)";

I think your insert command is out of order. I thought it would have been
c2000, c4000, c4001

But it appears that there isn't a consistency in your order. In your create statement it is c2000, c4000, c4001. So it is very easy to see where you might have gotten an order wrong somewhere.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Jason Wu
Greenhorn

Joined: Sep 03, 2002
Posts: 13
Thanks for your reply.Have u tried my code.if you do ,you will find that the result is really out of order.
Originally posted by Mark Spritzler:

I think your insert command is out of order. I thought it would have been
c2000, c4000, c4001

But it appears that there isn't a consistency in your order. In your create statement it is c2000, c4000, c4001. So it is very easy to see where you might have gotten an order wrong somewhere.
Mark
Lipman Li
Ranch Hand

Joined: May 02, 2002
Posts: 122
do not have chinese env, do not know how to set up the Env same with u.
Is it possible OS cause the problem?
Jason Wu
Greenhorn

Joined: Sep 03, 2002
Posts: 13
My NLS_CHARACTERSET of oracle816 is ZHS16GBK.
does it cause the problem?who can help me?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem of using setCharacterStream method to insert varchar2 data in oracle816