PostgreSQL - 安装JDBC驱动程序 [英] PostgreSQL - Installing JDBC driver
问题描述
/usr/local/pgsql/share/java/postgresql.jar 。
然后教程讨论使用这段代码:
Class.forName(org.postgresql.Driver);
然而,由于我是新来的postgreSQL,我不知道我应该把这一行,如果这是正确的。
我的问题是,没有将jar文件移动到这个位置,为了安装JDBC驱动程序,我实际需要做些什么我的postgreSQL安装?
编辑:这是我的设置:
服务器1:
Tomcat + SOLR
服务器2:
PostgreSQL与JDBC驱动程序
服务器1上的SOLR通过JDBC驱动程序查询服务器2上的postgreSQL
最好将PostgreSQL驱动程序安装到tomcat \lib文件夹中。只需将驱动程序jar复制到PATH_TO_TOMCAT\lib
将这些东西添加到系统CLASSPATH不是一个好主意,因为你可以在类加载器中结束。这里是一个例子,你如何最终在jar / classpath地狱。
- 假设当前的应用程序使用postgres 9.1,并在系统上设置驱动程序CLASSPATH
- 您决定在另一个应用程序上运行另一个应用程序,该应用程序与较新版本的postgres相提并论9.2版
- 因为您正在使用系统类路径应用程序2将最终使用旧的驱动程序,因为SYSTEM classpath倾向于优先于应用程序类路径,除非应用程序启动器脚本将CLASSPATH =清空系统类路径或使用不执行父级加载的自定义类加载器。
请参阅 http://tomcat.apache.org/tomcat-7.0-doc/jndi-datasource-examples-howto.html
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");
However, since I am new to postgreSQL I have no idea where I should be putting this line, or if this is even correct.
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?
EDIT: This is my setup:
Server 1: Tomcat + SOLR
Server 2: PostgreSQL with JDBC driver
SOLR on server 1 queries postgreSQL on server 2 via the JDBC driver
It is best to install your PostgreSQL driver into tomcat\lib folder. Just copy the driver jar to PATH_TO_TOMCAT\lib
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.
- Suppose the current app uses postgres 9.1 and you setup the driver on the system CLASSPATH
- You decide to run another app on that box which talks to a newer version of postgres lets say version 9.2
- Because you are using the system classpath app 2 will end up using the old driver because the SYSTEM classpath tends to take precedence over an applications classpath unless the app launcher script sets CLASSPATH="" to empty out the system classpath or uses a custom class loader that does not do parent-first class loading.
See http://tomcat.apache.org/tomcat-7.0-doc/jndi-datasource-examples-howto.html
这篇关于PostgreSQL - 安装JDBC驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!