0

I try to connect to an Oracle database with Python, but it can't connect.

This is my code:

import cx_Oracle

class CustomDatabase(object):

    def getDataFromDatabase(self, connectDB, queryCommand, row):
            conn = cx_Oracle.connect(self.connectDB)
            cur = conn.cursor()
            cur.execute(self.queryCommand)
            res = cur.fetchone()
            i = 0
            while (i < self.row):
                if cur.rowcount == self.row:
                    print res
                res = cur.fetchone()
                i = i + 1
            cur.close()
            conn.close()
            return res

    a = CustomDatabase()
    b = a.getDataFromDatabase("'Bell', 'pwd1234#', '191.168.1.10:1111/MyName'","select * from Mybook",5)

Below is the error I get:

Error show "AttributeError: 'CustomDatabase' object has no attribute 'connectDB'

Any advice on this matter?

1 Answer 1

1

On the first glance it looks like you made a typo

it should be:

 def getDataFromDatabase(self, connectDB, queryCommand, row):
     conn = cx_Oracle.connect(connectDB)
     cur = conn.cursor()
     ...

instead of:

def getDataFromDatabase(self, connectDB, queryCommand, row):
    conn = cx_Oracle.connect(self.connectDB)
    cur = conn.cursor()
    ...

You are using self and the object doesn't have attribute connectDB.

Also I can see that later you are using self.queryCommand and self.row this will fail as well, it should be replaced with queryCommand and row respectively.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.