How to List All Tables Stored in a SQL Server Backup (.BAK) File using Java

Cloudmersive
2 min readOct 6, 2022

--

Looking for an easy way to list SQL tables from a SQL Backup (.BAK) file, without opening the MS SQL Database engine? We have you covered. The List All Tables iteration of our SQL BackupConvert API will allow you to return structured information about all tables within any given .BAK file, including the schemaName & tableName. All you need to do is include your inputFile path and call the API with a valid Cloudmersive API key (which you can get by registering a free account on our website). For your reference, I’ve included an example response model JSON below:

{
"successful": true,
"tables": [
{
"schemaName": "string",
"tableName": "string"
}
]
}

In the remainder of this article, I’ll demonstrate how you can call this API using ready-to-run Java code examples. Just copy & paste, and you’re good to go.

The first step is to install the API client. We can do so by adding a reference to the repository in pom.xml:

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

And we can complete installation by adding an additional reference to the pom.xml dependency:

<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v4.25</version>
</dependency>
</dependencies>

Now we can call the function, beginning by adding the imports to the top of our file. Include your API key and inputFile path where indicated by the code comments, and you’re done:

// Import classes:
//import com.cloudmersive.client.invoker.ApiClient;
//import com.cloudmersive.client.invoker.ApiException;
//import com.cloudmersive.client.invoker.Configuration;
//import com.cloudmersive.client.invoker.auth.*;
//import com.cloudmersive.client.BackupConvertApi;
ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: Apikey
ApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");
Apikey.setApiKey("YOUR API KEY");
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//Apikey.setApiKeyPrefix("Token");
BackupConvertApi apiInstance = new BackupConvertApi();
File inputFile = new File("/path/to/inputfile"); // File | Input file to perform the operation on
try {
MssqlBakEnumerateTablesResult result = apiInstance.dataintegrationBackupConvertMssqlBakGetTablesPost(inputFile);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling BackupConvertApi#dataintegrationBackupConvertMssqlBakGetTablesPost");
e.printStackTrace();
}

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet