Posted By:
X_F
Posted On:
Monday, August 12, 2002 06:14 PM
my develop env: Oracle + classes12.zip + Weblogic 6.0 sp1 + JDK1.3.1 + Linux when i use updatable ResultSet to update a column value like this: ... PreparedStatement pstmt = conn.PreparedStatement("select name, score from student where id = ?", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); pstmt.setInt(1, id); ResultSet rs = pstmt.executeQuery(); ... String newName = new String(name.getBytes("GBK"), "ISO-8859-1"); rs.updateString(1, newName); //here will throw a SQLException:Cannot map Unicode to Oracle character. rs.updateRow(); //or here will thow the SQLException
More>>
my develop env:
Oracle + classes12.zip + Weblogic 6.0 sp1 + JDK1.3.1 + Linux
when i use updatable ResultSet to update a column value like this:
...
PreparedStatement pstmt = conn.PreparedStatement("select name, score from student where id = ?", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
pstmt.setInt(1, id);
ResultSet rs = pstmt.executeQuery();
...
String newName = new String(name.getBytes("GBK"), "ISO-8859-1");
rs.updateString(1, newName);
//here will throw a SQLException:Cannot map Unicode to Oracle character.
rs.updateRow();
//or here will thow the SQLException
....
en, my client is based on Chinese OS, so when fetch String from db , i must convert it to GBK like this:
...
String name = new String(rs.getString("name").getBytes("ISO-8859-1"), "GBK");
...
JTextField nameFld = new JTextField();
nameFld.setText(name);
...
my db's character is 'ISO-8859-1'.
when i write data into db, i must convert it to ISO-8859-1 at first. Always, the following fragment run correctly:
...
PreparedStatement pstmt = conn.prepareStatement("update student set name = ? where id = ?");
pstmt.setString(1, new String(name.getBytes("GBK"), "ISO-8859-1"));
pstmt.setInt(2, id);
pstmt.executeUpdate();
//run ok!
....
but why use Updatable ResultSet to perform update like my first article will throw SQLException?
<<Less