Problem of using setCharacterStream method to insert varchar2 data in oracle816 [message #106184] |
Mon, 11 November 2002 16:58 |
Jason Wu
Messages: 1 Registered: November 2002
|
Junior Member |
|
|
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;
}
}
|
|
|