
Convert Excel Workbook to SQL Script in Java.
Excel spreadsheets are excellent for organizing data but they are not ideal for dynamic queries, scalability, or integration with applications. Therefore, the conversion of Excel files to SQL format bridges this gap by enabling seamless migration of data into relational databases. This conversion allows you to leverage the power of SQL for advanced data manipulation, querying, and integration, making it an essential step for building robust and scalable data-driven solutions.
Excel to SQL Conversion API
Aspose.Cells Cloud SDK for Java provides a robust and efficient solution for converting Excel spreadsheets to SQL files. The API supports a wide range of Excel formats, including XLS, XLSX, and CSV, ensuring compatibility with various file types. With its advanced features, the SDK allows users to customize the conversion process, such as specifying particular worksheets, filtering data, or mapping columns to SQL table structures.
Installation
Please add the following details to pom.xml file of maven build project.
<repositories>
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://repository.aspose.cloud/repo/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-cells-cloud</artifactId>
<version>24.9</version>
</dependency>
</dependencies>
- You can download the latest version from the Aspose Repository.
Now, we need to obtain our client credentials from cloud dashboard. If you do not have an existing account, simply create a free account by following the instructions specified in the quick start article.
Convert Excel to SQL File in Java
In this section, we are going to explore the details on how to programmatically convert an Excel workbook to SQL file using Java code snippet:
CellsApi api = new CellsApi(clientId,clientSecret);
Create an instance of CellsApi while providing client credentials as input arguments.
api.uploadFile("input.xls", file, "internal");
Upload the source Excel workbook to the cloud storage using uploadFile(…) method.
File response = api.cellsWorkbookGetWorkbook(name, null ,format,
null, null, null, "internal", "myResultant.sql", "internal", null);
Finally, call the method cellsWorkbookGetWorkbook(…) to initiate the conversion operation.
A preview of an Excel to SQL file conversion.
XLS to SQL File using cURL Commands {#(#xls-sql-java)}
Aspose.Cells Cloud enables quick and efficient Excel-to-SQL conversion using simple cURL commands, making it an ideal solution for developers who prefer lightweight and scriptable workflows. This approach allows you to directly interact with the API from the command line, eliminating the need for complex setups or additional libraries.
The first step in this approach is to generate a JWT access token using the following command:
curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=XXXXXXX-b195-426c-85f7-XXXXXXXX&client_secret=XXXXXXXXXXXXXXXXXXXXXXXXX" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"
Once we have the JWT access token, please execute the following command to export Excel workbook to SQL file.
curl -v "https://api.aspose.cloud/v3.0/cells/{sourceFile}/SaveAs?newfilename={myResultant}&isAutoFitRows=false&isAutoFitColumns=false&checkExcelRestriction=false" \
-X POST \
-H "accept: application/json" \
-H "authorization: Bearer {accessToken}" \
-H "Content-Type: application/json" \
-d "{ \"SaveFormat\": \"sql\",}"
Replace sourceFile
with the name of input Excel workbook available in the cloud storage, myResultant
with the name of resultant SQL file and accessToken
with JWT access token generated above.
In order to save the resultant SQL file to local drive, please execute the following cURL command.
curl -v "https://api.aspose.cloud/v3.0/cells/{sourceFile}?format=SQL&isAutoFit=false&onlySaveTable=false" \
-X GET \
-H "accept: application/json" \
-H "authorization: Bearer {accessToken}" \
-o "myResultant.sql"
Free Excel to SQL Converter
In order to quickly witness the capabilities of our REST APIs, please try using our lightweight and supper-efficient Excel to SQL File Conversion App. This free App is built on top of Aspose.Cloud APIs and can be tested online without any installation requirements.
Free Excel to SQL conversion App.
Conclusion
Converting Excel to SQL is a crucial step in modernizing data management and enabling seamless database integration. Both methods ensure high accuracy, scalability, and secure handling of data. Whether you’re building data-driven applications or streamlining workflows, Aspose.Cells Cloud simplifies the process. Try it today to experience hassle-free and efficient Excel-to-SQL conversions!
Useful Links
Related Articles
We highly recommend visiting the following blogs: