1 24 25 package org.objectweb.cjdbc.scenario.tools.testlet; 26 27 import java.sql.Connection ; 28 import java.sql.ResultSet ; 29 30 37 public class ColumnUpdateTestLet extends AbstractConnectionTestLet 38 { 39 40 45 public ColumnUpdateTestLet(Connection con) 46 { 47 super(con); 48 config.put(TABLE_NAME, "ADDRESS"); 49 config.put(COLUMN_NAME, "ID"); 50 config.put(UPDATED_COLUMN_VALUE, "emmanuel"); 51 config.put(SELECTED_COLUMNS, "FIRSTNAME"); 52 config.put(USE_PREPARED_STATEMENT, "true"); 53 config.put(USE_TRANSACTIONS,"false"); 54 } 55 56 59 public void execute() throws Exception 60 { 61 String selectQuery = "select " + config.get(SELECTED_COLUMNS) + " from " 62 + config.get(TABLE_NAME) + " where " + config.get(COLUMN_NAME) + "=0"; 63 String updateQuery = "update " + config.get(TABLE_NAME) + " set " 64 + config.get(SELECTED_COLUMNS) + "='" 65 + config.get(UPDATED_COLUMN_VALUE) + "' where " 66 + config.get(COLUMN_NAME) + "=0"; 67 ResultSet rs1, rs2; 68 69 70 if (usePreparedStatement()) 71 { 72 if(useTransaction()) 73 jdbcConnection.setAutoCommit(false); 74 rs1 = jdbcConnection.createStatement().executeQuery(selectQuery); 75 jdbcConnection.createStatement().executeUpdate(updateQuery); 76 rs2 = jdbcConnection.createStatement().executeQuery(selectQuery); 77 if(useTransaction()) 78 jdbcConnection.commit(); 79 } 80 else 81 { 82 if(useTransaction()) 83 jdbcConnection.setAutoCommit(false); 84 rs1 = jdbcConnection.prepareStatement(selectQuery).executeQuery(); 85 jdbcConnection.createStatement().executeUpdate(updateQuery); 86 rs2 = jdbcConnection.prepareStatement(selectQuery).executeQuery(); 87 if(useTransaction()) 88 jdbcConnection.commit(); 89 } 90 91 assertTrue("No results", rs1.next()); 92 String laura = rs1.getString((String ) config.get(SELECTED_COLUMNS)); 93 assertEquals("Was expecting Laura", laura, "Laura"); 94 95 assertTrue("No results", rs2.next()); 96 String emmanuel = rs2.getString((String ) config.get(SELECTED_COLUMNS)); 97 System.out.println(emmanuel); 98 assertEquals("Was expecting Emmanuel", emmanuel, (String ) config.get(UPDATED_COLUMN_VALUE)); 99 } 100 101 } | Popular Tags |