The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
June 2000

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:

CODE for Java with MS Access

Posted by RajeshKanann on June 22, 2000 at 11:18 AM

Hi,

If you decided to use the MS Access with JAVA , you should've to create the DSN in all the client's machine what are all supposed to use that application.

YOu can use the following code to connect to databse using Access in JAVA.

Regards,
Rajesh

//////////////////// CODE STARTS HERE ////////////

public class DataBase
{
static String url = "jdbc:odbc:test" ; // test is the DSN
static String message;
static String query=null;
ResultSet rs;
Connection connection;


public DataBase(){
try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("contacted");
connection = DriverManager.getConnection(url);
System.out.println("Connection established");
}catch(Exception ex)
{
message = "Exception during SQL query: " + ex.toString();
ex.printStackTrace(System.out);
}

}


////////////// CODE ENDS HERE////////////////

After this just create the instance of this class and call the method.

Regards,

Rajesh




Replies:

Sponsored Links



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