Connect Oracle,sqlserver and PostgreSQL via JDBC under Linux

Source: Internet
Author: User

Today just need to statistics three Web site column information update situation, and these three sites in the background using a different database management system. The initial idea is to access the three backend databases through JDBC and generate reports based on the returned data by creating a small tomcat webapp.

1 development environment

    • Database management system: One is SQL Server 2000, the other is Oracle 9i, and one is PostgreSQL9.1
    • Tomcat Execution platform: CentOSx64 + jdk7.0x64 (full 64-bit environment)
2 selection of the JDBC driver 2.1 oracle9iOracle provides the Ojdbc6.jar this type 4 JDBC driver, and only this one file will be able to complete support for JDBC and copy it to Web-inf/lib. The key code is as follows:  Class.forName ("Oracle.jdbc.driver.OracleDriver");
Drivermanager.registerdriver (New Oracle.jdbc.driver.OracleDriver ());
String Dburl = "Jdbc:oracle:thin: @IP Address: 1521: instance Name";

 Oracle is doing very well for compatibility, and this version of the JDBC driver still supports oracle9i.   2.2 SqlServer2000Microsoft also provides SQL Server's type 4 JDBC driver, specifically two files: Sqljdbc4.jar, Sqljdbc.jar, with 4 is the latest version can run under JDK7.0, without 4 version cannot run onJDK7, the problem is that Sqljdbc4.jar only supports SQL Server version 2005 or more, and SQL Server 2000 is not supported. In other words, if you want to operate SQL Server 2000 with the JDBC driver provided by Microsoft, your JDK version must be lower than JDK7, but our development environment has determined that it is JDK7. There are two solutions to this idea: one is to use the Jdbc-odbc Bridge, UNIXODBC is the ODBC implementation on the Linux platform, and then need to install SQL Server 2000 ODBC driver, Www.unixODBC.org gave two links, one is not free open source, and the other is based on the FreeTDS ODBC driver, I do not know why www.freetds.org site is not open. I used to use the FreeTDS command line to connect SQL Server is still good. The configuration of ODBC is very complex, especially in the Linux environment, particularly unfriendly. Lazy psychology, gave up the idea.  second, since FREETDS can operate SQL Server, why not over ODBC, so that JDBC directly based on TDs, is lucky to find a good solution on the Internet: Jtds, see http://jtds.sourceforge.net. This project provides a JDBC implementation based on the TDS protocol, which is a pure type 4 JDBC driver, with a jtds-1.3.0.jar to satisfy the need to access SqlServer2000 through JDBC. And can run under the JDK7.0, just meet my requirements.  Finally, the second way of thinking, the key code is as follows:  Class.forName ("Net.sourceforge.jtds.jdbc.Driver");
Drivermanager.registerdriver (New Net.sourceforge.jtds.jdbc.Driver ());
String Dburl = "JDBC:JTDS:SQLSERVER://IP address: 1433/database name";
2.3 PostgreSQL9.1

Official website jdbc.potgresql.org provides Postgresql-9.2-1000.jdbc4.jar, which is also a type 4 JDBC driver that can be downloaded for use. The key code is as follows:

Class.forName ("Org.postgresql.Driver");
Dburl = "JDBC:POSTGRESQL://IP address: 5432/database name";

This driver is automatically registered when it is loaded, so it does not need to be registerdriver separately.

3 Summarywith this little project, summarize the JDBC driver choices for the database you are currently using:(1) SQL Server for 2005 and later, the proposed use of Microsoft's official type 4JDBC driver, for the 2000 version, if the JDK environment is older, you can use the official Microsoft version, if JDK7.0 use Jtds this type 4JDBC driver; (2) Oracle, it is recommended to use the official thin driver for all versions, that is, the type4 JDBC driver;(3) PostgreSQL, MYSQL, the official provide the type 4 JDBC driver, use can. The network is a treasure, but to find what you really need, you must have a complete knowledge architecture, must have a clear analytical thinking. If you need to access SQL Server and Oracle under the. NET Framework, you can refer to one of my other blogs: http://blog.csdn.net/smstong/article/details/5874451
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.