16 min to complete
In two previous lessons, Coding with Java Part 1 and Part 2, we explained how to use the Java driver to create applications that interact with ScyllaDB. Division 3 has decided to explore the Java programming language a bit further and came across an interesting feature of ScyllaDB that would allow us to store files in the database. With this ability, we can store images of the mutants in the catalog keyspace. With the images stored, Division 3 can see what the mutant looks like whenever they want and even share the image and tracking details with local law enforcement officials if needed.
A table in ScyllaDB supports a wide array of data types such as timestamp, text, integer, UUID, blob, and more. The blob datatype stores binary data in a table. For Division 3’s use case, we will add a blob column to the catalog.mutant_data table and store images for each mutant there using a Java application. Since ScyllaDB is a distributed system with fault protection and resiliency, storing files in ScyllaDB will have the same benefits as storing our existing data, based on the keyspace’s replication factor.
In the next section, you’ll review the code before running the lab.
The Java Example
Let’s understand what the code is doing. When you run the application, it will add two columns to the catalog.mutant_data table: b and m. Column b is the blob column where the binary file is stored, and column m is used to record the file’s name.
The container has an image file for each mutant, which the Java application will read and store in ScyllaDB according to their names.
The following functions will read the file and store it in a memory buffer, and then insert it into the table using a prepared statement:
The final step for the Java application is to read the data from ScyllaDB and write the data to /tmp. The select query fetches the blob column and sorts it by the primary keys (first_name and last_name).
Next, run the lab in the virtual environment.
Coding with Python
With the coding part done, let’s set up the ScyllaDB Cluster and then run the sample application in the lab
Conclusion
In this lesson, we reviewed the different data types that someone can use in their database tables and learned how to store binary files in ScyllaDB with a simple Java application. By being able to store images in ScyllaDB, Division 3 will be able to quickly see what a mutant looks like and can share the details with local law enforcement if needed. With the ability to store files in the Mutant Monitoring System, the possibilities are endless for how Division 3 can continue to evolve the system. Please be safe out there and continue to monitor the mutants!