The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
September 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Here is a DSNless method that works(at least for fox pro and access!)

Posted by Wade Chandler on November 15, 2001 at 3:14 PM

> How can i program JDBC using jdbc odbc bridge driver, using file dsn or dsnless connection..

I couldn't get the bridge to let me use a DSN, so I improvised a bit. I said. I will pass in the info it needs. The error I was getting from the Driver said that the data source was not found and that no "DEFAULT DRIVER was specified", so I did this. I created a file DSN. Then I took the options and seperated them with the semicolon(;). For the actual DSN name if you noticed, I left it blank and just put a semicolon in front of it. This got passed to the Microsoft odbc manager, and worked like a charm. This particular code runs with a Fox Pro db(free directory table), but will work other ODBC drivers as well, as long as you get the options for the driver correct. If you mess up the options you will get errors. Well, I hope this helps you out and many other people out all the same. READ BELOW FOR THE CODE!

Here is the code(You will have to work out the database and make sure you have it, or change the code):

import java.sql.*;
import java.util.*;

public class odbc
{//class odbc

public static void main(String args[])
{//main

try
{//try

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
java.sql.Connection conctn = DriverManager.getConnection("jdbc:odbc:;DRIVER=Microsoft FoxPro VFP Driver (*.dbf);"+
"UID=;"+
"Deleted=Yes;"+
"Null=Yes;"+
"Collate=Machine;"+
"BackgroundFetch=Yes;"+
"Exclusive=No;"+
"SourceType=DBF;"+
"SourceDB=C:\\ChildPlus\\CONS");
java.sql.Statement statmnt = conctn.createStatement();
java.sql.ResultSet reslts = statmnt.executeQuery("Select * from zcn");
while(reslts.next())
{//while
System.out.println("Name: " + reslts.getString("cntrname"));
}//end while

}//end try
catch(Exception e)
{//catch
e.printStackTrace();
System.out.println("Well, something really didn't work out that well!!!");
}//end catch


}//end main

}//end class odbc




Replies:
  • Thanks! Patrick January 16, 2002 at 1:23 PM (1)
    • :-) Abdool February 13, 2002 at 5:54 AM (0)

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us