question

JeffvG-0844 avatar image
0 Votes"
JeffvG-0844 asked NanavatiSarang-7225 commented

How can I insert a pandas DataFrame into Azure SQL Database with JDBC?

What is the correct way to use the JDBC Spark modules to insert a 4k row pandas DataFrame into Azure SQL Server? I see many questions like this on StackOverflow, but the answers are generally "it can't be done" or are overly complicated. It's difficult to believe that this is not a core use case of Azure Databricks.

azure-databricks
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

PRADEEPCHEEKATLA-MSFT avatar image
0 Votes"
PRADEEPCHEEKATLA-MSFT answered NanavatiSarang-7225 commented

Hi @JeffvG-0844,

Thanks for the question and using MS Q&A platform.

Looks like you cannot insert a pandas DataFrame into Azure SQL Database using JDBC.

When I tried using JDBC it returns - Query returned no results.

I would suggest try using the pyodbc package.

117808-image.png

This article - Insert Python dataframe into SQL table describes how to insert a pandas dataframe into a SQL database using the pyodbc package in Python.

Hope this helps. Do let us know if you any further queries.


Please "Accept the answer" if the information helped you. This will help us and others in the community as well.


image.png (74.3 KiB)
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @JeffvG-0844,

Just checking in to see if the above answer helped. If this answers your query, do click Accept Answer and Up-Vote for the same. And, if you have any further query do let us know.

0 Votes 0 ·

Hi @JeffvG-0844,

Following up to see if the above suggestion was helpful. And, if you have any further query do let us know.

0 Votes 0 ·
NanavatiSarang-7225 avatar image NanavatiSarang-7225 PRADEEPCHEEKATLA-MSFT ·

Is there a way to do a create table (w/o defining the table) and insert the pandas dataframe in one go to Azure SQL?

Within Azure SQL, you can do this as "Select into table1 from table2". Feel there must be a way to do something similar within python where you execute a query such as "Select into azureSQLtable1 from pandasdataframe " w/o the need of creating table and selecting each row item in a loop.

0 Votes 0 ·