Connecting to the database

Learn how to connect to the databases and tables in the databases.

Procedure

  • For an ODBC connection, follow the steps that are described in Installing and configuring ODBC.

    Now, you can connect to databases and tables.

    • To connect to a database, run:
      from nzpyida import IdaDataBase, IdaDataFrame
      idadb = IdaDataBase(DATASOURCE NAME, USERNAME, PASSWORD)
    • To connect to a table in that database, run:
      idadf = IdaDataFrame(idadb, TABLE NAME)
  • For a JDBC connection:
    1. Follow the instructions that are described in Installing and configuring JDBC.
    2. After you download and install the nzjdbc3.jar file, you must include its location in the value of the CLASSPATH environment variable.
      export CLASSPATH=PATH TO nzjdbc3.jar:$CLASSPATH

    Now, you can connect to databases and tables.

    • To connect to a database, run:
      from nzpyida import IdaDataBase, IdaDataFrame
      jdbc_dsn = jdbc:netezza://IP ADDRESS:PORT/DATABASE NAME"
      idadb = IdaDataBase(jdbc_dsn, uid="USRENAME", pwd="PASSWORD")
    • To connect to a table in that database, run:
      idadf = IdaDataFrame(idadb, TABLE NAME)
  • For an nzpy connection, if you have nzpyida, you do not have to install drivers on the client side as with the ODBC and JDBC connections.

    nzpyida supports a native Python driver nzpy-based connection for Netezza Performance Server.

    You can declare connection credentials in the following format.
    nzpy_dsn = {
            "database":DATABASE NAME,
             "port" :5480,
            "host": SERVER NAME,
            "securityLevel":0,
            "logLevel":0
           }
    Where:
    database
    Specifies the name of the database.
    host
    Specifies the IP address of the nz server.
    port
    Specifies the port at which the nz server is running at.

    Now, you can connect to databases and tables.

    • To connect to a database, run:
      from nzpyida import IdaDataBase, IdaDataFrame
      idadb = IdaDataBase(nzpy_dsn, uid="USERNAME", pwd="PASSWORD")
    • To connect to a table in that database, run:
      idadf = IdaDataFrame(idadb, TABLE NAME)