java.lang.ClassNotFoundException:org.netezza.Driver

Posted

技术标签:

【中文标题】java.lang.ClassNotFoundException:org.netezza.Driver【英文标题】:java.lang.ClassNotFoundException: org.netezza.Driver 【发布时间】:2012-05-29 13:31:40 【问题描述】:

我正在尝试使用 JDBC 驱动程序连接到 Netezza 数据库并执行简单的 SELECT 查询。我的项目的 lib 文件夹中有 nzjdbc.jar 文件(使用 eclipse),但出现以下错误。

 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)

这是我的代码:

 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();
            
    



 

【问题讨论】:

【参考方案1】:

在 Eclipse 中,您需要将 jar 添加到“构建路径”中的库中

Eclipse documentation

Tutorial

【讨论】:

以上是关于java.lang.ClassNotFoundException:org.netezza.Driver的主要内容,如果未能解决你的问题,请参考以下文章