Tuesday, June 14, 2016

Netezza JDBC Program

Netezza JDBC Program

Steps to connect to Netezza Database using Java (JDBC) program

Download the Netezza driver nzjdbc.jar

Connect to Eclipse and upload the nzjdbc.jar using "Build Path" as shown in below images




Java Class to connect to Netezza Database and read table data

---------------------------------------------------
package sample;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JdbcNetezzaConnection {

    public static void main(String[] args) {

        Connection conn1 = null;
        Statement statement = null;

        try {
            Class.forName("org.netezza.Driver");
            conn1 = DriverManager.getConnection("jdbc:netezza://servername/databasename", "username","password");
            if (conn1 != null) {
                System.out.println("Connected with connection #1");
            }
         // Create the statement to be used to get the results.
            statement = conn1.createStatement();
            // Create a query to use.
            String query = "select tablename, owner from _v_table where owner = 'ADMIN' limit 10";
            ResultSet resultSet = statement.executeQuery(query);

            System.out.println("Printing result...");
            while (resultSet.next()) {
             String tn = resultSet.getString("tablename");
             String opg = resultSet.getString("owner");
             System.out.println("\tablename: " + tn + ",  owner: " + opg );
         }

        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        } catch (SQLException ex) {
            ex.printStackTrace();
        } finally {
            try {
                if (conn1 != null && !conn1.isClosed()) {
                    conn1.close();
                }
            } catch (SQLException ex) {
                ex.printStackTrace();
            }
        }
    }
}

----------------------------------------------------

Output of the above class


Output from Netezza Database


15 comments:

  1. Your blog is the best place to gain knowledge on Java programming. Keep following my profile for IT trainings and languages studies.
    Regards:
    java courses in chennai with placement
    free java training in chennai

    ReplyDelete
  2. Thanks for the informative article. This is one of the best resources I have found in quite some time. Nicely written and great info. I really cannot thank you enough for sharing.

    rpa training in marathahalli

    rpa training in btm

    rpa training in kalyan nagar

    rpa training in electronic city

    rpa training in chennai

    rpa training in pune

    rpa online training

    ReplyDelete
  3. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    Python training in usa
    Python training in marathahalli
    Python training in pune

    ReplyDelete
  4. Hmm, it seems like your site ate my first comment (it was extremely long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog. I as well as an aspiring blog writer, but I’m still new to the whole thing. Do you have any recommendations for newbie blog writers? I’d appreciate it.
    Best Selenium Training in Chennai | Selenium Training Institute in Chennai | Besant Technologies


    ReplyDelete
  5. It's interesting that many of the bloggers to helped clarify a few things for me as well as giving.
    Most of ideas can be nice content.The people to give them a good shake to get your point and across the command.
    data science online training
    python online training
    uipath online training
    data science with python online training
    rpa online training

    ReplyDelete
  6. Thank you for benefiting from time to focus on this kind of, I feel firmly about it and also really like comprehending far more with this particular subject matter. In case doable, when you get know-how, is it possible to thoughts modernizing your site together with far more details? It’s extremely useful to me.

    Microsoft Azure online training
    Selenium online training
    Java online training
    Java Script online training
    Share Point online training


    ReplyDelete
  7. Grab the Digital Marketing Training in Chennai from Infycle Technologies, the best software training institute, and Placement center in Chennai which is providing professional software courses such as Data Science, Artificial Intelligence, Cyber Security, Big Data, Java, Hadoop, Selenium, Android, and iOS Development, DevOps, Oracle, etc with 100% hands-on practical training. Dial 7502633633 to get more info and a free demo and to grab the certification for having a peak rise in your career.

    ReplyDelete