Initializing A ResultSet

Initializing A ResultSet

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

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

ResultSet is an interface of which a subclass is instantiated in a JDBCdriver-specific manner.You have three main options. You can write your own dummy JDBCdriver, you can write your own dummy ResultSet implementation thatcan be populated with test data, or you can create a dummy databaseand use a real JDBC driver. Of all of your options, the third is themost desirable. There is really no reason to be writing a prototypewithout a test database. There are JDBC drivers for everything fromAccess files to Open Source databases such as PostgreSQL. Workingwith a test database from the get go is less time consuming thanwriting your own JDBC test classes and should produce a betterprototype since your development environment will more accuratelyrepresent your eventual deployment environment.

That said, if youare working with limited computing resources and cannot use a testdatabase, you should be able to implement your own JDBC 2.0 dummyResultSet class for testing purposes in a non-excessive amount oftime.

See also  Does It Make Sense to Splurge on a Laptop?

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist