English 中文(简体)
未找到装载JDBC org.postgresql的班级。 司机
原标题:Class not found loading JDBC org.postgresql.Driver

Im在网络项目上工作,我最近安装了9.1.1号邮局。

邮政服务器正在运行。 我可以像往常一样通过纸浆连接,从8.5台的垃圾堆放场上装满和适当节省所有物品。

So I also downloaded the JDBC4 driver for 9.1 postgres version here: http://jdbc.postgresql.org/download/postgresql-jdbc-9.1-901.src.tar.gz

我在“java”公路上通过ec片使用项目特性。

这是我用来提供其他班次的干 connection联系的法典(即,它是一个单一州,只有在现有物品已经关闭或无效的情况下,我才获得新的联系,而现在只有某个物体在某个时间关闭。)

public abstract class DBConnection {
private static Connection connection = null;

public static void connect() {
    try {
        if (connection == null) {
            String host = "127.0.0.1";
            String database = "xxxxx";
            String username = "xxxxx";
            String password = "xxxxx";
            String url = "jdbc:postgresql://" + host + "/" + database;
            String driverJDBC = "org.postgresql.Driver";
            Class.forName(driverJDBC);
            connection = DriverManager.getConnection(url, username,
                    password); //line firing the class not found exception

        } else if (connection.isClosed()) {
            connection = null;
            connect();
        }
    } catch (SQLException e) {
        e.printStackTrace(System.err);
    } catch (Exception e) {
        e.printStackTrace(System.err);
    }
}

public static void disconnect() {
    if (connection != null) {
        try {
            connection.close();
        } catch (SQLException e) {
            Logger.getLogger(DBConnection.class.getName()).log(
                    Level.SEVERE, null, e);
        }
        }
    }

    public static Connection getConnection() {

        try {
            if (connection != null && !connection.isClosed()) {
                return connection;
            } else {
                connect();
                return connection;
            }
        } catch (SQLException e) {
            Logger.getLogger(DBConnection.class.getName()).log(Level.SEVERE,
                    null, e);
            return null;
        }
    }

    @Override
    public void finalize() {
        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException e) {
                Logger.getLogger(DBConnection.class.getName()).log(
                        Level.SEVERE, null, e);
            }
        }
    }

}

正如我在管理该项目时在标题中写的那样,一个班子要求与这一类别挂钩,我总是获得一个非专业创始例外,因为它显然能够装上org.postgresql.司机。 驾驶员位于项目~/lib/org的分数位数。postgresql-9.1-901.jdbc4.jar,而且正如我所说的那样,在建筑道路上,通过粗略项目财产。

I m还提供样本查询,以了解我的班子通常接触DBConnection的行为:

public static final User validateUserCredentials(String id, String pswd) {
    Connection connection = DBConnection.getConnection();
    Logger.getLogger(Credentials.class.getName()).log(Level.SEVERE, (connection!=null)?"connection not null":"connection null");
    Statement stmt = null;
    Logger.getLogger(Home.class.getName()).log(Level.SEVERE, "validating credentials for user: username : " + id + " password : " + pswd);
    String sql = "Select * from fuser where id =  " + id + " ";
    ResultSet resultset = null;
    try {
        stmt = connection.createStatement();
        resultset = stmt.executeQuery(sql);
        Logger.getLogger(Credentials.class.getName())
                .log(Level.SEVERE, sql);
        resultset.next();
        String password = resultset.getString("pswd");
        if (pswd.equals(password))
            return new User(id, pswd);
    } catch (SQLException ex) {

        Logger.getLogger(Credentials.class.getName()).log(Level.SEVERE,
                null, ex);
    } finally {
        if (stmt != null)
            stmt = null;

        if (resultset != null)
            resultset = null;
        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException e) {

            }
            connection = null;
        }
    }
    return null;
}
最佳回答

I m working on a web project and I recently installed postgres 9.1.1

......

I在“java”建造道路上添加利用项目特性。 ∗ E/CN.6/2009/1。

这是错误的。 该联合报告必须贴在<代码>/WEB-INF/lib的网络项目夹中,同时不干扰项目特性中的Build Path。 该笔记本是网络应用时间段的标准部分。


<> Unrelated to the specific problem: 页: 1 DBConnection category。 页: 1 使用连接池,从来不把<条码>/条码>(北<条码>声明/条码>或<条码>ResultSet)作为类别/内容变量。 更正应作在后面的<条码>栏目中,并填写。 此外,你还发现了Kingk的注射孔。 使用<代码>PreparedStatement , 而不是压缩机载中的用户控制变量。

See also:

问题回答

在您的日程中增加这一依赖性:

    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.4-1203-jdbc4</version>
    </dependency>

第一件事是没有包装,确认驾驶员确实在座标有<条码>。 我在考察杰尔夫德尔和相关地点时注意到,有9.x jar号邮政,其中包含<代码>。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签