Hi All,

I've added support to the JDBCSampler to call Store Procedures. This then enables, Selects, Updates and Calls via JDBC. I won't bore you all with the reasons why and bloat this email. You can read about it at http://blog.arabx.com.au/?p=149

Attached are SVN patches as per your guidelines. I've not used SVN before, nor submitted to an Apache project, so please advise if I've missed some guidelines.

In addition, your online document reference doesn't presently match the screen in Version 2.1.1. The current binary version has Query Type [Select, Update], rather then Query Only [True|False] at http://jakarta.apache.org/jmeter/usermanual/component_reference.html#JDBC_Request

Regards

Ronald Bradford
http://www.arabx.com.au
Index: JDBCSampler.java
===================================================================
--- JDBCSampler.java	(revision 388876)
+++ JDBCSampler.java	(working copy)
@@ -23,6 +23,7 @@
 import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
 import java.sql.Statement;
+import java.sql.CallableStatement;
 
 import org.apache.avalon.excalibur.datasource.DataSourceComponent;
 import org.apache.jmeter.samplers.Entry;
@@ -45,6 +46,8 @@
 
 	public static final String QUERY = "query";
 	public static final String SELECT = "Select Statement";
+	public static final String UPDATE = "Update Statement";
+	public static final String STATEMENT = "Call Statement";
 
 	public String query = "";
 
@@ -69,6 +72,7 @@
 		log.debug("DataSourceComponent: " + pool);
 		Connection conn = null;
 		Statement stmt = null;
+		CallableStatement cs = null;
 
 		try {
 
@@ -88,14 +92,19 @@
 					Data data = getDataFromResultSet(rs);
 					res.setResponseData(data.toString().getBytes());
 				} finally {
-					if (rs != null) {
-						try {
-							rs.close();
-						} catch (SQLException exc) {
-							log.warn("Error closing ResultSet", exc);
-						}
-					}
+					close(rs);
 				}
+			// execute stored procedure
+			} else if (STATEMENT.equals(getQueryType())) {
+				try {
+					cs = conn.prepareCall(getQuery());
+					cs.execute();
+					String results = "Executed";
+					res.setResponseData(results.getBytes());
+				} finally {
+					close(cs);
+				}
+			// Insert/Update/Delete statement
 			} else {
 				stmt.execute(getQuery());
 				int updateCount = stmt.getUpdateCount();
@@ -112,20 +121,8 @@
 			res.setResponseMessage(ex.toString());
 			res.setSuccessful(false);
 		} finally {
-			if (stmt != null) {
-				try {
-					stmt.close();
-				} catch (SQLException ex) {
-					log.warn("Error closing statement", ex);
-				}
-			}
-			if (conn != null) {
-				try {
-					conn.close();
-				} catch (SQLException ex) {
-					log.warn("Error closing connection", ex);
-				}
-			}
+			close(stmt);
+			close(conn);
 		}
 
 		res.sampleEnd();
@@ -164,6 +161,38 @@
 		return data;
 	}
 
+	public static void close(Connection c) {
+		try {
+			if (c != null) c.close();
+		} catch (SQLException e) {
+			log.warn("Error closing Connection", e);
+		}
+	}
+	
+	public static void close(Statement s) {
+		try {
+			if (s != null) s.close();
+		} catch (SQLException e) {
+			log.warn("Error closing Statement", e);
+		}
+	}
+
+	public static void close(CallableStatement cs) {
+		try {
+			if (cs != null) cs.close();
+		} catch (SQLException e) {
+			log.warn("Error closing CallableStatement", e);
+		}
+	}
+
+	public static void close(ResultSet rs) {
+		try {
+			if (rs != null) rs.close();
+		} catch (SQLException e) {
+			log.warn("Error closing ResultSet", e);
+		}
+	}
+
 	public String getQuery() {
 		return query;
 	}
Index: JDBCSamplerBeanInfo.java
===================================================================
--- JDBCSamplerBeanInfo.java	(revision 388876)
+++ JDBCSamplerBeanInfo.java	(working copy)
@@ -50,7 +50,7 @@
 		p.setValue(NOT_UNDEFINED, Boolean.TRUE);
 		p.setValue(DEFAULT, JDBCSampler.SELECT);
 		p.setValue(NOT_OTHER,Boolean.TRUE);
-		p.setValue(TAGS,new String[]{JDBCSampler.SELECT,"Update Statement"});
+		p.setValue(TAGS,new String[]{JDBCSampler.SELECT,JDBCSampler.UPDATE,JDBCSampler.STATEMENT});
 
 		p = property("query");
 		p.setValue(NOT_UNDEFINED, Boolean.TRUE);

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to