Using jTDS to connect to a Windows SQL DB from AIX

The jTDS drivers may be easier to configure than freeTDS in your unix environment to allow database updates to windows. You have to compile the source yourself, but you would be doing in java rather than C. Here is a link to sourceforge:

jTDS sourceforge
If this doesn’t work, I have a version of the jar file that it would compile and also the subdirectories of compiled class code which I know runs at AIX 5.3:

jtds-1.2.jar

jtds-1.2.tar

The following example script will make a simple database connection and is pretty self-explanatory, it requires that the ‘net’ directory structure exist because I am not clever enough to figure out how to use jar files yet and I just un-jarred it with the -x command:

/* 
Copyright 2003 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
Use of this software is authorized pursuant to the terms of the license found at
http://developer.java.sun.com/berkeley_license.html.

Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

- Redistribution of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

- Redistribution in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

Neither the name of Sun Microsystems, Inc. or the names of contributors may
be used to endorse or promote products derived from this software without
specific prior written permission.

This software is provided "AS IS," without a warranty of any kind.
ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICORSYSTEMS, INC. ("SUN")
AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN
IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

You acknowledge that this software is not designed, licensed or intended for
use in the design, construction, operation or maintenance of any nuclear
facility.


*/


/*
 * Copyright 2003 Sun Microsystems, Inc.  ALL RIGHTS RESERVED.
 * Use of this software is authorized pursuant to the terms of the license found at
 * http://developer.java.sun.com/berkeley_license.html.
 */

import java.sql.*;
import net.sourceforge.jtds.jdbc.*;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;


class MS_SQL_Execute {

  public static void main(String args[]) {

    String url = "jdbc:jtds:sqlserver://nad0019st01:1433/DBAReporting";
    Connection con;
    Statement stmt;
    String query = "";
    String lastcol = "";

    File file = new File("execute.sql");

FileInputStream fis = null;
    BufferedInputStream bis = null;
    DataInputStream dis = null;

    try {
      fis = new FileInputStream(file);

      // Here BufferedInputStream is added for fast reading.
      bis = new BufferedInputStream(fis);
      dis = new DataInputStream(bis);

      // dis.available() returns 0 if the file does not have more lines.
      while (dis.available() != 0) {

      // this statement reads the line from the file and print it to
        // the console.

        query = dis.readLine();
        System.out.println(query);


    try {
      Class.forName("net.sourceforge.jtds.jdbc.Driver");

    } catch(java.lang.ClassNotFoundException e) {
      System.err.print("ClassNotFoundException: ");
      System.err.println(e.getMessage());
    }

    try {
      con = DriverManager.getConnection(url,
                   "AIXUser", "P@ssw0rd");

      stmt = con.createStatement();

  /*    stmt.executeUpdate("insert into SUPPLIERS " +
                   "values(49, 'Superior Coffee', '1 Party Place', " +
         "'Mendocino', 'CA', '95460')");
 */
      ResultSet rs = stmt.executeQuery(query);

/*
      ResultSetMetaData rsmd = rs.getMetaData();
        int numColumns = rsmd.getColumnCount();

// Get the column names; column indices start from 1
        String FirstcolumnName = rsmd.getColumnName(1);
        for (int i=2; i
					

unixODBC/freetds on p5 suse to connect to SQLServer

I was able to compile freetds-0.64 on SUSE (2.6.16.21-0.8-ppc64).
Then I compiled unixODBC to make use of it.

Use tsql to check your connection:

jrigler:/usr/local/bin> tsql -H $host -p $port -U $user -P $password
locale is “en_US.UTF-8”
locale charset is “UTF-8”
1

Now set up odbc.ini so that isql will work:

jrigler@nad0019linux01:/usr/local/etc> more odbc.ini
[ODBC Data Sources]

[DBAR]
Driver = /usr/local/lib/libtdsodbc.so
Description = DBAReporting
Trace = Yes
Server = nad0019st01.brinksinc.com
Database = DBAReporting
Port = 1433
TDS_Version = 8.0
DontDLClose = 1

Finally you can test your connection with isql:

isql -v $DATASOURCE $USER $PASSWORD