1 2 25 26 package org.objectweb.cjdbc.scenario.tools.testlet; 27 28 import java.sql.Clob ; 29 import java.sql.Connection ; 30 import java.sql.PreparedStatement ; 31 import java.sql.ResultSet ; 32 33 39 public class ClobTestLet extends AbstractConnectionTestLet 40 { 41 42 47 public ClobTestLet(Connection con) 48 { 49 super(con); 50 config.put(TABLE_NAME, "BLOB"); 51 config.put(UPDATED_COLUMN_VALUE, "I am a CLOB"); 52 config.put(COLUMN_NAME, "blob"); 53 } 54 55 58 public void execute() throws Exception 59 { 60 String ss = (String ) config.get(UPDATED_COLUMN_VALUE); 61 String tableName = (String ) config.get(TABLE_NAME); 62 String columnName = (String ) config.get(COLUMN_NAME); 63 64 String insertQuery = "Insert into " + tableName + " values(3,?)"; 65 PreparedStatement ps; 66 if (useCJDBCClass()) 67 { 68 Clob clob = new org.objectweb.cjdbc.driver.Clob(ss); 69 ps = jdbcConnection.prepareStatement(insertQuery); 70 ps.setClob(1, clob); 71 ps.executeUpdate(); 72 } 73 else 74 { 75 ps = jdbcConnection.prepareStatement(insertQuery); 76 ps.setString(1, ss); 77 ps.executeUpdate(); 78 } 79 ps = jdbcConnection.prepareStatement("Select * from " + tableName + " where id=3"); 81 ResultSet rs = ps.executeQuery(); 82 rs.first(); 83 Clob rsclob = rs.getClob(columnName); 84 String ret = rsclob.getSubString(0, (int) rsclob.length()); 85 if (ret.equalsIgnoreCase(ss) == false) 86 { 87 fail("Retrieved:" + ret + " is different from:" + ss); 88 } 89 String clob2 = "I am a clob as well"; 91 PreparedStatement ps1 = jdbcConnection.prepareStatement("Insert into " + tableName 92 + " values(4,?)"); 93 ps1.setString(1, clob2); 94 ps1.executeUpdate(); 95 96 PreparedStatement ps2 = jdbcConnection.prepareStatement("Select * from " + tableName 97 + " where id=4"); 98 ResultSet rs2 = ps2.executeQuery(); 99 rs2.first(); 100 Clob rs2clob = rs2.getClob(columnName); 101 String ret2 = rs2clob.getSubString(0, (int) rs2clob.length()); 102 if (ret2.equalsIgnoreCase(clob2) == false) 103 { 104 fail("Retrieved:" + ret2 + " is different from:" + clob2); 105 } 106 107 } 108 109 } | Popular Tags |