Working with JDBC

VuGen provides full support for the JDBC protocol which is used for defining how a client may access a database.

Note: Support for Java 8 only.

Supported Databases

The JDBC protocol supports all databases used via standard JBDC interface.

It also has custom support for non-standard usage of following databases:

  • Postgres
  • MySQL
  • Oracle
  • MSSQL
  • H2

Back to top

Recording JDBC Scripts

To record JDBC script use the Java Record Replay protocol.

In Recording Options, under Recording Protocol > Recorder Options, select JDBC and record as with any Java Record Replay script.

To avoid long and repetitive scripts, configure VuGen to generate loops where necessary by selecting Recording Protocol > Code Generation Options > Search for loops.

For more information, see about recording Java Record Replay scripts, see Java Record Replay Protocol Recording Tips.

Back to top

Limitations

  • Blob and Clob class recording is not supported.
  • Advanced non-standard features ae not supported.

Back to top

Sample Script

import lrapi.lr;

public class Actions{
                
	public int action() throws Throwable{
		_properties1 = System.getProperties();
		_properties1.put("com.hpe.lr.java2.record.format", "XML");
		System.setProperties(_properties1);
		
		_driver1 = new org.h2.Driver();
		_driver2 = org.h2.Driver.load();
	
		_string1 = "jdbc:h2:~/test";
		_string2 = "user";
		_string3 = lr_unmask("3fbae0ecdbfa75c3");
		_connection1 = java.sql.DriverManager.getConnection(_string1, _string2, _string3);
		
		_string4 = "SELECT count(1) FROM USERS";
		_preparedstatement1 = _connection5.prepareStatement(_string4);
		
		_resultset1 = _preparedstatement1.executeQuery();
		
		_boolean1 = _resultset1.next();
		
		_int1 = _resultset1.getInt(1);
		_connection1.close();

		return 0;
	}// end of method: public int action() throws Throwable

	public int init() throws Throwable{
		return 0;
	}// end of method: public int init() throws Throwable

	public int end() throws Throwable{
		return 0;
	}// end of method: public int end() throws Throwable

	/* ------ fields ------ */
	
	java.util.Properties _properties1;
	org.h2.Driver _driver1;
	org.h2.Driver _driver2;
	java.lang.String _string1;
	java.lang.String _string2;
	java.lang.String _string3;
	java.sql.Connection _connection1;
	
	java.lang.String _string4;
	java.sql.PreparedStatement _preparedstatement1;
	java.sql.ResultSet _resultset1;
	boolean _boolean1;
	int _int1;
}

Back to top