I am trying to connect pandas to Oracle as below(I already downloaded oracle client):
import pandas as pd
import cx_Oracle
username='a'
password='d'
host_name = 'aa.com'
service_name= 'ss'
dsn = cx_Oracle.makedsn(host=host_name,port=1535,sid=None,service_name=service_name)
con = cx_Oracle.connect(user=username, password=password, dsn= dsn ,encoding = "UTF-8", nencoding = "UTF-8")
my_sql_query=(""" SELECT * FROM schema.tbl1 WHERE ROWNUM =1 """)
##1- Directly reading SQL to Pandas
#Read SQL via Oracle connection to Pandas DataFrame
df = pd.read_sql(my_sql_query, con=con)
I get:
Cannot locate a 64-bit Oracle Client library: "C:\oracle\product\11.2.0\client_1\bin\oci.dll is not the correct architecture". See https://oracle.github.io/odpi/doc/installation.html#windows for help
When I click the link shown in the message, it asks me to run some .exe file. What is this file going to do?
You need to make sure that Python, cx_Oracle and the Oracle client libraries are all the same 64-bit or 32-bit architecture. It sounds like you have a mis-match.
The link given in the error is for HTML documentation; it doesn't run an exe file. The documentation mentions a VS Redistributable is needed - which is an exe file. This is a Microsoft package needed by Oracle Instant Client.
Related
My Requirement: Save the SQL query output (received the data) in to the local drives in csv file format.
My OS: Windows 10 64 bit
VS Code 1.67.1:
I have installed the following extensions to connect with snowflake data warehouse:
SQL Tools
Snowflake driver for SQL Tools
I have successfully connected my snowflake (cloud) data warehouse and received the data at
the VS code.
What I want is to save (export) the output (received the data) to the local file (for example to D:\result\result.csv).
How can I achieve that?
image attached for your reference.
thank you all.
pmk
If you can run a bit of python, this does pretty much what you need
import snowflake.connector
import csv
conn = snowflake.connector.connect(
user='',
password='',
account='',
warehouse='',
database='',
schema='',
role=''
)
results = conn.cursor().execute("""MY QUERY""").fetchall()
csvfile = open(r"PATH TO FILE",'a', newline='')
output = csv.writer(csvfile)
output.writerows(results)
csvfile.close
I'm trying to Generate Multiple files Table Structure to Snowflake via Python
I have list of files in Directory, I want to read data from files create the tables dynamically in snowflake using file names.
below is what I tried so far
# Generate Multiple files Table Structure to Snowflake via Python
import os
from os import path
import pandas as pd
import snowflake.connector
from snowflake.sqlalchemy import URL
from sqlalchemy import create_engine
from snowflake.connector.pandas_tools import write_pandas, pd_writer
dir = r"D:\Datasets\users_dataset"
engine = create_engine(URL(
account='<account>',
user='<user>',
password='<password>',
role='ACCOUNTADMIN',
warehouse='COMPUTE_WH',
database='DEM0_DB',
schema='PUBLIC'
))
connection = engine.connect()
connection.execute("USE DATABASE DEMO_DB")
connection.execute("USE SCHEMA PUBLIC")
results = connection.execute('USE DATABASE DEMO_DB').fetchone()
print(results)
# read the files from the directory and split the filename and extension
for file in os.listdir(dir):
name, extr = path.splitext(file)
print(name)
file_path = os.path.join(dir, file)
print(file_path)
df = pd.read_csv(file_path, delimiter=',')
df.to_sql(name, con=engine, index=False)
I'm getting below error
sqlalchemy.exc.ProgrammingError: (snowflake.connector.errors.ProgrammingError) 090105 (22000): Cannot perform CREATE TABLE. This session does not have a current database. Call 'USE DATABASE', or use a qualified name.
[SQL:
CREATE TABLE desktop (
"[.ShellClassInfo]" FLOAT
)
]
(Background on this error at: https://sqlalche.me/e/14/f405)
I checked for permission issues on snowflake, and I haven't found any issues.
Can someone please help with this error
At the create_engine the database is called DEM0_DB instead of DEMO_DB:
engine = create_engine(URL(
...
#database='DEM0_DB',
database='DEMO_DB',
schema='PUBLIC'
))
UPDATE. This is a known bug - pandas.read_sas breaks if trying to read a SAS7bdat as an iterable.
I receive an error while attempting pandas.read_sas on pandas 0.18.1 in Spyder 3.0.1, Windows 10.
I generated a simple dataset in SAS and saved in the SAS7bdat format:
data basic;
do i=1 to 20;
j=i**2;
if mod(i,2) then type='Even';
else type='Odd';
output;
end;
run;
We save this data to a directory.
The following code successfully imports the SAS dataset when run in Python:
import pandas
f=pandas.read_sas('basic.sas7bdat')
The following code fails:
import pandas
for chunk in pandas.read_sas('basic.sas7bdat', chunksize=1):
pass
The error generated is
File "C:\Program Files\Anaconda3\lib\site-packages\pandas\io\common.py", line 101, in __next__
raise AbstractMethodError(self)
AbstractMethodError: This method must be defined in the concrete class of SAS7BDATReader
The same error is produced if I use the option iterable=True, or if I use both iterable= and chunksize= together.
Relevant documentation: http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_sas.html
Sample SAS7bdat datasets: http://www.principlesofeconometrics.com/sas.htm.
I am totally new in oracle world and need help.
I installed oracle free version OracleXE112_Win64 and has got a dump file that I need to import.
Is there anyone who can guide me how to do it?
Thank's
Can someone tell me what happens here when I import the dump file. I get the following:
Username: system
Password:
Connected to: Oracle Database 11g Express Edition Release 11.2.0.2.0 - Production Import data only (yes/no): no > yes
Import file: EXPDAT.DMP > C:\Buildings22.dmp
Enter insert buffer size (minimum is 8192) 30720> 30720
Export file created by EXPORT:V11.01.00 via conventional path
Warning: the objects were exported by Buildings22, not by you
import done in WE8MSWIN1252 character set and AL16UTF16 NCHAR character set
import server uses AL32UTF8 character set (possible charset conversion)
List contents of import file only (yes/no): no > yes
IMP-00402: Invalid parameter "SHOW" with data_only mode
IMP-00000: Import terminated unsuccessfully
How can I check if I import a dump file?
How can I display the content of dump file, tables in Oracle SQL Developer?
I apologize for the issues, but I really brand new in oracle?
Hello i'm trying to get a mysql database connection with jython.
I'm using Python 3.3.2 and Jython 2.5.3
My code looks like this:
import sys
from java.sql import *
sys.path.append("C:\\dev\\git\\LogAnalysis\\mysql-connector-java-5.0.8.jar")
con = DriveManager.getConnection("jdbc:mysql://localhost:3306/statistik", "root", "admin")
stmt = con.createStatement()
rs = stmt.executeQuery("SELECT * FROM search")
and so on. (Only a code snippet)
Each time i get the exeption:
java.sql.SQLException: java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/statistik
Can someone give me a tip?
See solution at: Jython CLASSPATH, sys.path and JDBC drivers
For me the easiest solution is to provide batch/shell script which sets CLASSPATH. This looks like:
SET CLASSPATH=C:\dev\git\LogAnalysis\mysql-connector-java-5.0.8.jar;%CLASSPATH%
CALL jython your_program.py %1 ...
Then you can remove line with:
sys.path.append(...)