In this tutorial we will be walking you through how you can connect to your databases whether it might be Relational – SQL Server, Oracle, DB2, MySQL, PostgreSQL or Big Data – Hive, Apache Spark, or SaaS – Salesforce, Eloqua etc., using an ODBC driver. As an example, we will show you how you can connect to SQL Server using DataDirect ODBC driver.
Have Julia installed on your machine
julia> Pkg.add("ODBC")
julia> ODBC.drivers()
julia> ODBC.dsns()
db
=
ODBC.DSN(
"SQLServer"
,
"username"
,
"password"
)
df
=
ODBC.query(db,
"SELECT * FROM Chinook.dbo.Artist"
)
println(df)
csv
=
ODBC.query(db,
"select * from Chinook.dbo.Artist"
, CSV.Sink,
"Artists.csv"
)
ODBC.execute!(db,
"CREATE TABLE [Chinook].[dbo].[Artist2]([ID] [INT] NOT NULL,[Name] [nvarchar](120) NULL)"
)
ODBC.execute!(db,
"INSERT INTO Artist2 VALUES (472, 'Saikrishna Bobba')"
);
ODBC.disconnect!(db)
using ODBC
using CSV
#list all drivers
println(ODBC.drivers())
#list all ODBC DSNS
println(ODBC.dsns())
#Connect to ODBC DSN
db
=
ODBC.DSN(
"SQLServer"
,
"username"
,
"password"
)
#Query your Database, return result as dataframe
df
=
ODBC.query(db,
"SELECT * FROM Chinook.dbo.Artist"
)
println(df)
# Query your database, return result as CSV file
csv
=
ODBC.query(db,
"select * from Chinook.dbo.Artist"
, CSV.Sink,
"Artists.csv"
)
#Create Table
ODBC.execute!(db,
"CREATE TABLE [Chinook].[dbo].[Artist2]([ID] [INT] NOT NULL,[Name] [nvarchar](120) NULL)"
)
#Load data
ODBC.execute!(db,
"INSERT INTO Artist2 VALUES (472, 'Saikrishna Bobba')"
);
#disconnect
ODBC.disconnect!(db)
Feel free to try any of our ODBC drivers to connect to your databases from Julia. If you have any questions or issues, please contact us.