• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Problem of using setCharacterStream method to insert varchar2 data in oracle816

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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;
}
}
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Jason Wu
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My NLS_CHARACTERSET of oracle816 is ZHS16GBK.
does it cause the problem?who can help me?
reply
    Bookmark Topic Watch Topic
  • New Topic