Re: ODBC confusion - Mailing list pgsql-novice
From | John Sokel |
---|---|
Subject | Re: ODBC confusion |
Date | |
Msg-id | 000601c018c5$8245a480$6464030a@insect.net Whole thread Raw |
In response to | ODBC confusion (" Kate Downie " <katedd@my-deja.com>) |
List | pgsql-novice |
I've been doing a lot of JDBC/ODBC programs lately with PostgreSQL, and my opinion is to stick with JDBC if you have it working. It is always better to use the native driver of the database itself. ODBC is basically a generic interface for your program, but there is still an underlying DB driver that actually interfaces with the DB. So using ODBC only adds one more layer into the picture. Plus ODBC is notoriously slower than the native driver. What it does attempt to give you is database independence in your application, although in my experience this is rarely the case since every database has it's own little syntax quirks. I always just use a switch statement at the beginning of my program to determine what database I am running, and load the correct driver, then I set a few globals for the database syntax differences differences (code snippet attached below). So my opinion is to not use ODBC unless all your SQL calls are fairly strait forward. But if you want to do it, it is as easy as running the Windows driver setup program (from postresql.org) to install the ODBC driver and then adding a DSN (from control panel) and any program that can use ODBC can use it. I'm not an expert on Linux or Perl using ODBC, hopefully someone else will answer you there. Hope this helps... ============================ My Java DB startup code: ============================ public class DBConn { private Connection con; // Database types public static final int POSTGRES = 1; public static final int ORACLE = 2; public static final int MSSQL = 3; public static final int MSACCESS = 4; // DB Type values public int DBType; // What type of database are we using public String sGetTS; // DB command to get current timestamp public DBConn (ConfigFile theConfig) { String sDBType = theConfig.getValueString("DB_TYPE", "postgres"); String sURL = theConfig.getValueString("DB_URL", "airsync"); String sHostName = theConfig.getValueString("DB_HOST", "localhost"); if (sDBType.equalsIgnoreCase("postgres")) { DBType = POSTGRES; sGetTS = "timestamp 'now'"; } else if (sDBType.equalsIgnoreCase("oracle")) { DBType = ORACLE; sGetTS = "SYSDATE"; } else if (sDBType.equalsIgnoreCase("mssql")) { DBType = MSSQL; sGetTS = "GetDate()"; } else if (sDBType.equalsIgnoreCase("msaccess")) { DBType = MSACCESS; sGetTS = "Date()+Time()"; } // load JDBC driver... try { String sClass="", sCon=""; switch (DBType) { case POSTGRES: sClass = "org.postgresql.Driver"; sCon = "jdbc:postgresql://" + sHostName + "/" + sURL; break; case ORACLE: sClass = "oracle.jdbc.driver.OracleDriver"; sCon = "jdbc:oracle:thin:@" + sHostName + ":"; sCon += theConfig.getValueString("DB_PORT", "1521") + ":"; sCon += theConfig.getValueString("DB_SID", "ORCL"); break; default: // Standard ODBC sClass = "sun.jdbc.odbc.JdbcOdbcDriver"; sCon = "jdbc:odbc:" + sURL; break; } Class.forName(sClass); con = DriverManager.getConnection(sCon, theConfig.getValueString("DB_USER_NAME", "dbuser"), theConfig.getValueString("DB_PASSWORD", "password")); } catch (Exception ex) { System.out.println("Could not connect to DB: " + ex.toString()); } } =================================== Hope this helps ----- Original Message ----- From: "Kate Downie" <katedd@my-deja.com> To: <pgsql-novice@postgresql.org> Sent: Thursday, September 07, 2000 2:50 AM Subject: [NOVICE] ODBC confusion > I'm unsure about where exactly the ODBC driver(s) fit into the picture > when it comes to accessing a PostgreSQL database. > > I want to learn to access PostgreSQL from my Linux and Windows machine. > (Linux machine is running PostgreSQL) with: > > 1. Java - already done this using the JDBC driver in my jdbcxxxxx.jar > file. I just copied this to my win machine and put it in my CLASSPATH. > > 2. Perl - I understand I can use DBI for this > > 3. C and C++ - there are library routines for this. > > > Is it possible to use an ODBC driver exclusively with programming > tools/languages instead of JDBC, DBI, libpg, libpg? > > > > > --== Sent via Deja.com http://www.deja.com/ ==-- > Before you buy.
pgsql-novice by date: