Link to home
Start Free TrialLog in
Avatar of Sean Milne
Sean Milne

asked on

Java Applet Conneting to MSAccess Database

How could I connect a java applet to an Access Database File?
I need to write an applet to search a list of phone numbers,email addresses and server them to the person who accessed the web page. I am a relative beginer so the more complete the answers the better.
ASKER CERTIFIED SOLUTION
Avatar of jpk041897
jpk041897

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of suhai
suhai

Java Applet can connect to MSAccess Database using JDBC-ODBC. If you using JDK1.1.1 just include in classpath(autoexec).
You have to download JDBC package if using JDK1.02. To communicate your applet & your database on browser, i suggest you Symantec dbAnywhere Server(Netscape only). Please refer to  
http://www.symantec.com 
check the documentation for dbAnywhere (configuration C for MSAccss) & download Trial dbAnywhere Server for testing.

SET PATH=C:\WINDOWS;C:\WINDOWS\COMMAND;C:\Jdk1.1.1\Bin;c:\jdk1.1.1\jdbc\classes\sun\jdbc\odbc;"%PATH%"
SET PATH=C:\WINDOWS;C:\WINDOWS\COMMAND;C:\jdk1.1.1\lib;C:\jdk1.1.1\jdbc;C:\jdk1.1.1\jdbc\classes;"%PATH%"
SET PATH=C:\dbANYWHERE Server\redist\dbaw.zip;C:\dbANYWHERE Server\redist\sql.zip;"%PATH%"

SET CLASSPATH=.;C:\JDK1.1.1\LIB\CLASSES.ZIP;C:\dbANYWHERE Server\redist\dbaw.zip;c:\dbANYWHERE Server\redist\sql.zip

Java applet/application:
public void setup()
{
 Connection myConnection;
 Statement myStmt;
 String url = "jdbc:odbc:yourdatabase"; //yourdatabase is example
 try                                  //use your own                                       //  source database
 {      
   Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
   myConnection = DriverManager.getConnection(url, " ", " ");
   myStmt = myConnection.createStatement();
 }
 catch (java.sql.SQLException e){
      System.out.println("SQL Pass Exception");
 }
 catch (java.lang.Exception e2){                          System.out.println("Java Lang Pass Exception");      
 }
}
for dbAnywhere connection:
driver =(Driver)Class.forName("symantec.itools.db.jdbc.Driver").newInstance();
DriverManager.registerDriver(driver);
String url = "jdbc:dbaw://192.168.0.9:8889/MS_Access/newdatabase/newdatabase";

String user = " ";
String password = " ";
con = DriverManager.getConnection(url,user,password);
stmt = con.createStatement();
   

You have to setup your database in Control Panel 32bitODBC and add MSAccess Driver .mdb(then select your database)
You can use SQL language to insert,delete,update from database
ex: Resutselt myresult;
    try{
      string sql = "select * from Emloyee where ....";
      myresult = myStmt.executeQuery(sql);  
      while(myresult.next())
      {
           myResult.getString("staffid");
      }
     catch (java.sql.SQLException e){
      System.out.println("SQL Pass Exception");
      }
     catch (java.lang.Exception e2){                                  System.out.println("Java Lang Pass Exception");      
     }

I suggest you to use Visual Cafe Pro to build & compile your applet.

I hope this help.

Pablo.