How could I read SQLite file which will be passed as MultipartFile parameter? (in java/kotlin)

286 Views Asked by At

I have to write REST API which will parse an SQLite file and parse&save its data into the server's MySQL DB.

The SQLite file will be passed as a .zip file(MultipartFile), so I have to unzip it, and then read the unzipped file as DTO.

The code will be as following..

fun parseSQLite(zipFile: MultipartFile) {
  val file = unzip(zipFile)

  val sqliteDB = somethingLibrary.load(file)

  doParseTable(sqliteDB.execute("select * from TestTable"))
}

I found there are sqlite-jdbc library(https://github.com/xerial/sqlite-jdbc), but it seems like it might not work in my case. I think I need mmap I/O, but are there any JAVA library for it?

Thanks!

1

There are 1 best solutions below

1
mozzi On

For those whom may face a similar problem; I decided to add a step that saves "unzipped SQLite DB" into the server's local storage, and then load DB from it.

it would be as to be following.

fun parseSQLite(zipFile: MultipartFile) {
  val fileName = unzipAndSaveToLocal(zipFile)
  
  val connection = DriverManager.getConnection("jdbc:sqlite:${testdir}/db/${fileName}");
  doParseTable(connection.createStatement().executeUpdate("select * from TestTable"))
}