/** Convience method for CHAR construction */ protected final CHAR toCHAR(String s) { // make sure if the string is larger than one character, only take the first character if (s.length() > 1) s = new String((new Character(s.charAt(0))).toString()); try { // BUG: make sure I am correct return new CHAR(s, CharacterSet.make(CharacterSet.ISO_LATIN_1_CHARSET)); } catch (SQLException e) { java.util.logging.Logger.getGlobal().log(java.util.logging.Level.INFO, "", e); } return null; }
@Override protected Object convertString(Column column, Field fieldDefn, Object data) { if (data instanceof CHAR) { return ((CHAR)data).stringValue(); } return super.convertString(column, fieldDefn, data); }
// Schema is : create table my_table (col1 char(10)); // insert into my_table values ('JDBC'); PreparedStatement pstmt = conn.prepareStatement ("select count() from my_table where col1 = ?"); ResultSet rs; pstmt.setString (1, "JDBC"); // Set the Bind Value rs = pstmt.executeQuery(); // This does not match any row // ... do something with rs CHAR ch = new CHAR("JDBC ", null); ((OraclePreparedStatement)pstmt).setCHAR(1, ch); // Pad it to 10 bytes rs = pstmt.executeQuery(); // This matches one row // ... do something with rs ((OraclePreparedStatement)pstmt).setFixedCHAR(1, "JDBC"); rs = pstmt.executeQuery(); // This matches one row // ... do something with rs
/** Convience method for CHAR construction */ protected final CHAR toCHAR( String s ) { // make sure if the string is larger than one character, only take the first character if (s.length() > 1) s = new String((new Character(s.charAt(0))).toString()); try { //BUG: make sure I am correct return new CHAR(s, CharacterSet.make(CharacterSet.ISO_LATIN_1_CHARSET)); } catch (SQLException e) { e.printStackTrace(); } return null; }