Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Databases
Expertise: Beginner
Feb 15, 2000



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Initializing A ResultSet

I am building a prototype but am trying to make the code as reuseable as possible. To test the prototype, I need to simulate a ResultSet being returned from a database. When my backend program simulating a database tries to add columns into the ResultSet, I get error messages that the ResultSet has not been initialized, which is true.

How would I go about initializing this ResultSet given that I have no database and am currently reading a file and trying to populate the ResultSet using methods within ResultSet.

ResultSet is an interface of which a subclass is instantiated in a JDBC driver-specific manner. You have three main options. You can write your own dummy JDBC driver, you can write your own dummy ResultSet implementation that can be populated with test data, or you can create a dummy database and use a real JDBC driver. Of all of your options, the third is the most desirable. There is really no reason to be writing a prototype without a test database. There are JDBC drivers for everything from Access files to Open Source databases such as PostgreSQL. Working with a test database from the get go is less time consuming than writing your own JDBC test classes and should produce a better prototype since your development environment will more accurately represent your eventual deployment environment.

That said, if you are working with limited computing resources and cannot use a test database, you should be able to implement your own JDBC 2.0 dummy ResultSet class for testing purposes in a non-excessive amount of time.

DevX Pro
Thanks for your registration, follow us on our social networks to keep up-to-date