1 24 25 package org.objectweb.cjdbc.scenario.tools.testlet; 26 27 import java.sql.CallableStatement ; 28 import java.sql.Connection ; 29 import java.sql.ResultSet ; 30 import java.sql.Statement ; 31 32 38 public class ProcedureTestLet extends AbstractConnectionTestLet 39 { 40 41 46 public ProcedureTestLet(Connection con) 47 { 48 super(con); 49 config.put(PROCEDURE_NAME, "SIN(100)"); 50 config.put(USE_PREPARED_STATEMENT, Boolean.FALSE); 51 config.put(USE_UPDATE_STATEMENT, Boolean.FALSE); 52 } 53 54 57 public void execute() throws Exception 58 { 59 boolean useStatement = ((Boolean ) config.get(USE_PREPARED_STATEMENT)) 60 .booleanValue(); 61 boolean useUpdate = ((Boolean ) config.get(USE_UPDATE_STATEMENT)) 62 .booleanValue(); 63 ResultSet rs = null; 64 int updated = -10; 65 String procedure = "{call " + config.get(PROCEDURE_NAME); 66 System.out.println(procedure); 67 if (useStatement) 68 { 69 CallableStatement cs = jdbcConnection.prepareCall(procedure); 70 if (!useUpdate) 71 rs = cs.executeQuery(); 72 else 73 updated = cs.executeUpdate(); 74 } 75 else 76 { 77 Statement statement = jdbcConnection.createStatement(); 78 if (!useUpdate) 79 rs = statement.executeQuery(procedure); 80 else 81 updated = statement.executeUpdate(procedure); 82 } 83 if (!useUpdate) 84 { 85 assertTrue("No result set", rs.next()); 86 String result = rs.getString(1); 87 System.out.println(result); 88 } 89 else 90 { 91 System.out.println(updated + " rows updated"); 92 assertTrue("Expected updated value:", updated >= -1); 93 } 94 } 95 96 } | Popular Tags |