jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From milam...@apache.org
Subject svn commit: r1700060 - in /jmeter/trunk: src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java xdocs/changes.xml
Date Sat, 29 Aug 2015 16:54:18 GMT
Author: milamber
Date: Sat Aug 29 16:54:17 2015
New Revision: 1700060

URL: http://svn.apache.org/r1700060
Log:
Use typed methods such as setInt, setDouble, setDate ... for prepared statement #27

Bugzilla Id: 58301

This closes #27


Modified:
    jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java?rev=1700060&r1=1700059&r2=1700060&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java
(original)
+++ jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java
Sat Aug 29 16:54:17 2015
@@ -21,13 +21,18 @@ package org.apache.jmeter.protocol.jdbc;
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.lang.reflect.Field;
+import java.math.BigDecimal;
 import java.sql.CallableStatement;
 import java.sql.Connection;
+import java.sql.Date;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
 import java.sql.Statement;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.sql.Types;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -321,7 +326,7 @@ public abstract class AbstractJDBCTestEl
                     if (argument.equals(NULL_MARKER)){
                         pstmt.setNull(i+1, targetSqlType);
                     } else {
-                        pstmt.setObject(i+1, argument, targetSqlType);
+                        setArgument(pstmt, argument, targetSqlType, i+1);
                     }
                 }
                 if (OUT.equalsIgnoreCase(inputOutput)||INOUT.equalsIgnoreCase(inputOutput))
{
@@ -338,6 +343,62 @@ public abstract class AbstractJDBCTestEl
         return outputs;
     }
 
+    private void setArgument(PreparedStatement pstmt, String argument, int targetSqlType,
int index) throws SQLException {
+        switch (targetSqlType) {
+        case Types.INTEGER:
+            pstmt.setInt(index, Integer.parseInt(argument));
+            break;
+        case Types.DECIMAL:
+        case Types.NUMERIC:
+            pstmt.setBigDecimal(index, new BigDecimal(argument));
+            break;
+        case Types.DOUBLE:
+        case Types.FLOAT:
+            pstmt.setDouble(index, Double.parseDouble(argument));
+            break;
+        case Types.CHAR:
+        case Types.LONGVARCHAR:
+        case Types.VARCHAR:
+            pstmt.setString(index, argument);
+            break;
+        case Types.BIT:
+        case Types.BOOLEAN:
+            pstmt.setBoolean(index, Boolean.parseBoolean(argument));
+            break;
+        case Types.BIGINT:
+            pstmt.setLong(index, Long.parseLong(argument));
+            break;
+        case Types.DATE:
+            pstmt.setDate(index, Date.valueOf(argument));
+            break;
+        case Types.REAL:
+            pstmt.setFloat(index, Float.parseFloat(argument));
+            break;
+        case Types.TINYINT:
+            pstmt.setByte(index, Byte.parseByte(argument));
+            break;
+        case Types.SMALLINT:
+            pstmt.setShort(index, Short.parseShort(argument));
+            break;
+        case Types.TIMESTAMP:
+            pstmt.setTimestamp(index, Timestamp.valueOf(argument));
+            break;
+        case Types.TIME:
+            pstmt.setTime(index, Time.valueOf(argument));
+            break;
+        case Types.BINARY:
+        case Types.VARBINARY:
+        case Types.LONGVARBINARY:
+            pstmt.setBytes(index, argument.getBytes());
+            break;
+        case Types.NULL:
+            pstmt.setNull(index, targetSqlType);
+            break;
+        default:
+            pstmt.setObject(index, argument, targetSqlType);
+        }
+    }
+
 
     private static int getJdbcType(String jdbcType) throws SQLException {
         Integer entry = mapJdbcNameToInt.get(jdbcType.toLowerCase(java.util.Locale.ENGLISH));

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1700060&r1=1700059&r2=1700060&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Sat Aug 29 16:54:17 2015
@@ -154,6 +154,7 @@ Summary
 <ul>
     <li><bug>58013</bug>Enable all protocols that are enabled on the default
SSLContext for usage with the SMTP Sampler.</li>
     <li><bug>58209</bug>JMeter hang when testing javasampler because HashMap.put()
is called from multiple threads without sync.</li>
+    <li><bug>58301</bug>Use typed methods such as setInt, setDouble, setDate
... for prepared statement #27</li>
 </ul>
 
 <h3>Controllers</h3>
@@ -199,6 +200,7 @@ Summary
 <li>Jérémie Lesage (jeremie.lesage at jeci.fr)</li>
 <li>Kirill Yankov (myworkpostbox at gmail.com)</li>
 <li>Amol Moye (amol.moye at thomsonreuters.com)</li>
+<li>Samoht-fr (https://github.com/Samoht-fr)</li>
 </ul>
 
 <br/>



Mime
View raw message