Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

I am trying to connect to a Netezza database using the JDBC driver and do a simple SELECT query. I have the nzjdbc.jar file in the lib folder in my project (using eclipse) and I am getting the following error.

 java.lang.ClassNotFoundException: org.netezza.Driver
 at java.net.URLClassLoader$1.run(Unknown Source)
 at java.net.URLClassLoader$1.run(Unknown Source)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.net.URLClassLoader.findClass(Unknown Source)
 at java.lang.ClassLoader.loadClass(Unknown Source)
 at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
 at java.lang.ClassLoader.loadClass(Unknown Source)
 at java.lang.Class.forName0(Native Method)
 at java.lang.Class.forName(Unknown Source)

Here is my code:

 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
 public class Tests {


public static void main(String[] args) 
{
    String server = "myhost.com";
    String port = "5480";
    String dbName = "dbname";
    String url = "jdbc:netezza://" + server + "/" + dbName ;
    String user = "user";
    String pwd = "pwd";
    Connection conn = null;
    Statement st = null;
    ResultSet rs = null;
    try {
        Class.forName("org.netezza.Driver");
        System.out.println(" Connecting ... ");
        conn = DriverManager.getConnection(url, user, pwd);
        System.out.println(" Connected "+conn);

        String sql = "SELECT COUNT(*) FROM TABLE";
        st = conn.createStatement();
        rs = st.executeQuery(sql);
        if(rs.next()) {
            System.out.println(rs.getString(1));
        } else {
            System.out.println(" No data found");
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            if( rs != null)
                rs.close();
            if( st!= null)
                st.close();
            if( conn != null)
                conn.close();
        } catch (SQLException e1) {
                e1.printStackTrace();
            }
    }

}

 }
share|improve this question
up vote 1 down vote accepted

In Eclipse you will need to add the jar to the libraries in your "Build path"

Eclipse documentation

Tutorial

share|improve this answer
    
Thanks. Appreciate it. – Ram May 29 '12 at 15:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.