PostgreSQL - 安装 JDBC 驱动程序 [英] PostgreSQL - Installing JDBC driver

查看:196
本文介绍了PostgreSQL - 安装 JDBC 驱动程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难确定应该如何在我的 debian 6.0 服务器上安装适用于 PostgreSQL 的 JDBC 驱动程序.我已将驱动程序 .jar 移至以下目录:

I'm having a hard time working out how I should be installing the JDBC driver for PostgreSQL on my debian 6.0 server. I have moved the driver .jar into the following directory:

/usr/local/pgsql/share/java/postgresql.jar. 

然后教程讲使用这段代码:

Then the tutorials talk about using this code:

Class.forName("org.postgresql.Driver");

但是,由于我是 postgreSQL 的新手,我不知道我应该把这条线放在哪里,或者这是否正确.

However, since I am new to postgreSQL I have no idea where I should be putting this line, or if this is even correct.

我的问题是,除了将 jar 文件移动到这个位置之外,我实际上需要做什么才能在我的 postgreSQL 安装中安装 JDBC 驱动程序?

My question is, short of moving the jar file to this location, what do I actually need to do in order to install the JDBC driver on my postgreSQL installation?

这是我的设置:

服务器 1:Tomcat + SOLR

Server 1: Tomcat + SOLR

服务器 2:带有 JDBC 驱动程序的 PostgreSQL

Server 2: PostgreSQL with JDBC driver

服务器 1 上的 SOLR 通过 JDBC 驱动程序查询服务器 2 上的 postgreSQL

SOLR on server 1 queries postgreSQL on server 2 via the JDBC driver

推荐答案

最好把你的PostgreSQL驱动安装到tomcatlib文件夹下.只需将驱动程序 jar 复制到 PATH_TO_TOMCATlib

It is best to install your PostgreSQL driver into tomcatlib folder. Just copy the driver jar to PATH_TO_TOMCATlib

将东西添加到系统 CLASSPATH 不是一个好主意,因为您可能会在类加载器地狱中结束.这是您如何最终陷入 jar/classpath 地狱的示例.

It is not a good idea to add things to the system CLASSPATH because you can end in class loader hell. Here is an example of how you end up in jar / classpath hell.

  • 假设当前应用使用 postgres 9.1,并且您在系统 CLASSPATH 上设置了驱动程序
  • 您决定在该机器上运行另一个应用程序,该应用程序与较新版本的 postgres 通信,比如说 9.2 版
  • 因为您使用的是系统类路径,所以应用 2 最终将使用旧驱动程序,因为 SYSTEM 类路径往往优先于应用程序类路径,除非应用启动器脚本设置 CLASSPATH="" 以清空系统类路径或使用不进行父类优先加载的自定义类加载器.

参见 http://tomcat.apache.org/tomcat-7.0-doc/jndi-datasource-examples-howto.html

这篇关于PostgreSQL - 安装 JDBC 驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆