Posts

Showing posts from 2013

Create BeanShell Script to Make Database call

BeanShell Script BeanShell is a small, free, embeddable Java source interpreter with object scripting language features, written in Java. BeanShell dynamically executes standard Java syntax and extends it with common scripting conveniences such as loose types, commands, and method closures like those in Perl and JavaScript. Following script make database connection and every iteration it takes 50 records from database and populate them in hashmap. This has been created to use with jmeter using beanshell sampler. import com.postgresql.jdbc.Driver; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import java.util.HashMap; import java.util.Map; System.out.println("Postgres Connect Example."); Connection conn = null; Statement stmt = null; ResultSet rs = null; String url = "jdbc:postgresql://192.168.3.99:5432/"; String dbName = "DB";