本文整理汇总了Java中java.sql.ResultSet.updateNString方法的典型用法代码示例。如果您正苦于以下问题:Java ResultSet.updateNString方法的具体用法?Java ResultSet.updateNString怎么用?Java ResultSet.updateNString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.sql.ResultSet
的用法示例。
在下文中一共展示了ResultSet.updateNString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testUpdateNString
import java.sql.ResultSet; //导入方法依赖的package包/类
/**
* Tests for ResultSet.updateNString()
*
* @throws Exception
*/
public void testUpdateNString() throws Exception {
createTable("testUpdateNString", "(c1 CHAR(10) PRIMARY KEY, c2 NATIONAL CHARACTER(10)) default character set sjis");
Properties props1 = new Properties();
props1.put("useServerPrepStmts", "true"); // use server-side prepared statement
props1.put("characterEncoding", "UTF-8"); // ensure charset is utf8 here
Connection conn1 = getConnectionWithProps(props1);
PreparedStatement pstmt1 = conn1.prepareStatement("INSERT INTO testUpdateNString (c1, c2) VALUES (?, ?)");
pstmt1.setString(1, "1");
pstmt1.setNString(2, "aaa");
pstmt1.execute();
Statement stmt1 = conn1.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
ResultSet rs1 = stmt1.executeQuery("SELECT c1, c2 FROM testUpdateNString");
rs1.next();
rs1.updateNString("c2", "bbb");
rs1.updateRow();
rs1.moveToInsertRow();
rs1.updateString("c1", "2");
rs1.updateNString("c2", "ccc");
rs1.insertRow();
ResultSet rs2 = stmt1.executeQuery("SELECT c1, c2 FROM testUpdateNString");
rs2.next();
assertEquals("1", rs2.getString("c1"));
assertEquals("bbb", rs2.getNString("c2"));
rs2.next();
assertEquals("2", rs2.getString("c1"));
assertEquals("ccc", rs2.getNString("c2"));
pstmt1.close();
stmt1.close();
conn1.close();
createTable("testUpdateNString", "(c1 CHAR(10) PRIMARY KEY, c2 CHAR(10)) default character set sjis"); // sjis field
Properties props2 = new Properties();
props2.put("useServerPrepStmts", "true"); // use server-side prepared statement
props2.put("characterEncoding", "SJIS"); // ensure charset isn't utf8 here
Connection conn2 = getConnectionWithProps(props2);
PreparedStatement pstmt2 = conn2.prepareStatement("INSERT INTO testUpdateNString (c1, c2) VALUES (?, ?)");
pstmt2.setString(1, "1");
pstmt2.setString(2, "aaa");
pstmt2.execute();
Statement stmt2 = conn2.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
ResultSet rs3 = stmt2.executeQuery("SELECT c1, c2 FROM testUpdateNString");
rs3.next();
try {
rs3.updateNString("c2", "bbb"); // field's charset isn't utf8
fail();
} catch (SQLException ex) {
assertEquals("Can not call updateNString() when field's character set isn't UTF-8", ex.getMessage());
}
rs3.close();
pstmt2.close();
stmt2.close();
conn2.close();
}