How to make apache2 authenticate against MS SQL 2000 Server - Page 2

Want to support HowtoForge? Become a subscriber!
 
Submitted by spats (Contact Author) (Forums) on Fri, 2007-01-12 19:20. ::

5. Tools and actual implementation

Looking around for sollution it turned out that connecting from Linux to MS SQL is not that straightforward. Ruby, perl, python - all have nice DBI (database interface modules) but when it comes to MS - it's getting painful.
Please correct me if i'm wrong.

I was aware that on the same Linux machine runs jboss application that is web interface to the same MS SQL database. So looking into direction of java seamed most appropriate solution.

5.1. connecting from Java to MS SQL

It took not that much gogling to find some samples and glue together the java ‘program’ that initially looked like that:

import java.sql.*;
import java.io.*;
public class testConnection
{
    public static void main(String[] args)
    {
      String userName;
      String userPass;
      userName = args[0];
      userPass = args[1];
    DB db = new DB();
        db.dbConnect(
     "jdbc:jtds:sqlserver://xxx.xxx.xxx.xxx:1433/test",userName,userPass);
    }
}
class DB
{
    public DB() {}
    public void dbConnect(String db_connect_string,
  String db_userid, String db_password)
    {
        try
        {
            Class.forName("net.sourceforge.jtds.jdbc.Driver");
            Connection conn = DriverManager.getConnection(
    db_connect_string, db_userid, db_password);
            System.out.println("connected");
        }
        catch (Exception e)
        {
            //e.printStackTrace();
            System.out.println("failed");
        }
    }
};

I've had already Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2) on that machine.
So only non out-of-the-box thing was net.sourceforge.jtds.jdbc.Driver part.
This is the driver that needs to be ‘installed’ to access MS SQL form java.
This project is located at http://jtds.sourceforge.net/ . I installed it like that:

wget http://belnet.dl.sourceforge.net/sourceforge/jtds/jtds-1.2-dist.zip
unzip jtds-1.2-dist.zip
cp jtds-1.2.jar /usr/lib/java/jre/lib/ext/

So now it’s possible to compile the program:

javac testConnection.java

and run it

java testConnection myUsername myPass

After that I looked out what can be done from apache's side.


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.