Applet direcrtly accessing a database.

In JDK1.1 it wasn't possible to give access to a database without using RMI, servlets or Socket based programming.
If I correctly interpret JDK1.2 security enhancements, one can give specific permissions in the policy file to enable the applet to connect and listen to any socket. Thus it should be possible to directly open a database connection from an Applet and fire queries to the database.

For Illustration, please help me in writing code for a JApplet in accessing an MSAccess database through JDBC-ODBC Bridge through one of its method which is called on the click of noe of its button.


pankajgAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

opabcCommented:
i have some good servlet links for u to view..
i am also doing about the same thing as you.

i am using applet to servlet communication with the servlet doing the connection to the database via JDBC.

i am not using the signed applet way coz i am doing this application for intranet use and i dun want to end up paying for nothing.

I am still developing the program.

Links
http://www.websiteresources.com/cgi-local/directory.cgi?command=showlinks&start=0&category=java+servlets

http://webreview.com/servlets/tutorials.html

http://www.math.hawaii.edu/~ralph/Servlets/

http://www.servletforum.com/

http://www.nikos.com/javatoys/deep/servlets/

http://www.j-nine.com/pubs/applet2servlet/

You can reach me at opabc@rocketmail.com
0
pankajgAuthor Commented:
I wnted to know how to do it without using servlets/rmi/socket programming as mentioned clearly in my Question. Is it possible to do it using policy file.
0
heyhey_Commented:
>> an MSAccess database through JDBC-ODBC Bridge

you need a configured ODBC datasource on the client machine and probably permissions to execute native code
0
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

pankajgAuthor Commented:
I forgot to mention that DSN is on the same  server machine as of  the web Server.
0
heyhey_Commented:
you need a configured ODBC DATASOURCENAME on the CLIENT machine.

that's ODBC - not magic.
0
Ravindra76Commented:

Hi,

1.first sign the applet.

 From: vladi21
 Date: Tuesday, November 16 1999 - 08:46PM CST  
 
http://java.sun.com/docs/books/tutorial/applet/overview/security.html 

Code signing resources:

Creating Signed, Persistent Java Applets
http://www.ddj.com/articles/1999/9902/9902h/9902h.htm 

http://www.javasoft.com/products/jdk/1.1/docs/guide/security/index.html 
http://java.sun.com/security/signExample/index.html 
http://www.verisign.com/library/guide/developer/signing/index.html 
http://www.suitable.com/Doc_CodeSigning.shtml 
http://www.securingjava.com/appdx-c/ 
http://tactika.com/realhome/javaht/java-s1.html 
http://www.fastlane.net/~tlandry/javafaq.txt 

MS:
http://www.thawte.com/support/developer/ms.html 
http://www.developer.com/journal/techworkshop/curr.html 
http://www.verisign.com/library/guide/developer/authenticode/index.html 
http://msdn.microsoft.com/library/psdk/crypto/cryptotools_6cdv.htm 
http://msdn.microsoft.com/library/psdk/crypto/portaltool_3u3p.htm 

NN:
http://developer.netscape.com/docs/manuals/signedobj/ 
http://developer.netscape.com/docs/manuals/signedobj/javadoc/Package-netscape_security.html 
http://developer.netscape.com/docs/manuals/signedobj/targets/contents.htm 
http://developer.netscape.com/support/faqs/objfaq.html 
http://developer.netscape.com/docs/manuals/deploymt/4_5PREFS.HTM 

NN: Bypass the need for a certificate
Netscape provides a way to accept a codebase as trusted (then a certificate is not needed). This can be useful during development or in a private Intranet. In the Netscape Users directory, there is a file called prefs.js. Adding the line user_pref("signed.applets.codebase_principal_support", true);

will enable JAR file without a certificate to request privileges on your machine. If you agree, it will be possible for an Applet to lauch a program, write a file on your hard disk or print on the printer. You will still have to ask for privileges in your program using the Netscape capabilites classes.
Another way is to lower general security setting to more allow more freedom when running applets locally. Add or modify the following entries in the prefs.js: user_pref("unsigned.applets.low_security_for_local_classes", true);
user_pref("signed.applets.local_classes_have_30_powers", true);
user_pref("signed.applets.low_security_for_local_classes", true);
user_pref("signed.applets.verbose_security_exception", true);


Then you don't need to asked for privileges for local classes.
When adding or modifying the file prefs.js, Netscape must not be running because your modification will be overwritten. So shut down Netscape, edit the prefs.js and then restart Netscape.
 
2.Create a dsn on client machine as told by heyhey.


a. Assume that your databse server(i.e  the system whch contain database ) is
abc.

b.Assume that your database ( data.mdb was presented in abc system def sirectory.

c.Create a dsn (assume myDsn) on every client connected to lan as

   1. net use somedrivername(assume f:)
      as database server.

     Eg: net use f: \\abc\c; ("c"  driectory).

  2.Create a dsn in start ->settings ->control panel ->odbc->msaccessdatabase->

 GIve dsn name as myDsn.

 give the path as f:\def\data.mdb.

That's all.

Best of luck

0
vladi21Commented:
http://java.sun.com/products/jdbc/faq.html


How can I use the JDBC API to access a desktop database like Microsoft Access over the network?

Most desktop databases currently require a JDBC solution that uses ODBC underneath. This is because the vendors of these database products haven't implemented all-Java JDBC drivers.


The best approach is to use a commercial JDBC driver that supports ODBC and the database you want to use. See the JDBC drivers page for a list of available JDBC drivers.

The JDBC-ODBC bridge from Sun's Java Software does not provide network access to desktop databases by itself. The JDBC-ODBC bridge loads ODBC as a local DLL, and typical ODBC drivers for desktop databases like Access aren't networked. The JDBC-ODBC bridge can be used together with the RMI-JDBC bridge , however, to access a desktop database like Access over the net. This RMI-JDBC-ODBC solution is free.
http://dyade.inrialpes.fr/mediation/download/ 

also look
http://java.sun.com/products/jdk/1.1/docs/guide/jdbc/index.html
http://java.sun.com/docs/books/jdbc/intro.html

Java how-to DB section!
http://tactika.com/realhome/javaht/java-d1.html
http://codeguru.developer.com/java/Miscellaneous/Database/index.shtml

0
Ravindra76Commented:
HI,

A sample code for rmi and jdbc



In sun site, you will get sample examples

//Remote Interface

import java.rmi.*;

public class RMIJdbc extends Remote
{
public String getDataFromServerDatabase() throws RemoteException;
}

// Implementation class (SERVER)

import java.rmi.*;
import java.rmi.server.*;
public class RMIJdbcImpl extends UnicastRemoteObject implements RMIJdbc
{
Connection con;
PreparedStatement pst;
ResultSet rs;
String hostname="localhost"; // where you run the rmi registry
int port = 1099; // the port of the rmiregistry (by default it takes 1099)
String objectname="server"; // your object name in the naming service(rmiregistry)
public RMIJdbcImpl()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:yourdsn");
}
catch ( Exception ee)
{
ee.printStackTrace();
}

public String getDataFromServerDatabase() throws RemoteException
{
String toReturn = "";
try
{
pst = con.prepareStatement("select ename from your table where empno=?)";
pst.setInt(1,100) //Assume yourtable contains like 100 as empno and //Rameshaa as ename
rs = pst.executeQuery();
if ( rs.next())
toReturn = rs.getString(1);
retrun toReturn;

}

public static void main(String args[])
{
RMIJdbcImpl server = new RMIJdbcImpl();
server.bindInNamingService();
}
public void bindInNamingService(){
try
{
Naming.rebind("rmi://"+hostname+":"+hostpor+"/"+objectname,this);
}
Catch ( Exception eee)
{
eee.printStackTrace();
}
}
}



// CLient class
import java.rmi.server.*;
import java.rmi.*;

public class RMIClient
{
public static void main(String args[])
{
try
{
RMIJdbc obj = Naming.lookup("rmi://"+args[0]+":"+args[1]+"/"+args[2]);
System.out.println(getDataFromServerDatabase());
}catch(Exception e){
e.printStackTrace();
}
}
}



Compiling:

javac RMIJdbc.java
javac RMIJdbcImpl.java

rmic RMIJdbcImpl

javac RMIClient.java

Running:

SERVER:

start rmiregistry ( you should keep the window open until you need your server)
java RMIJdbcImpl

CLIENT:

java RMIClient localhost 1099 server

( you can give the hostname where rmiregistry is running for your server the port is rmiregistry port
these params must be the same as you give in your server);


Best of luck
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pankajgAuthor Commented:
Though I was looking for a non RMI soln, but the this answer plus your earlier soln. completes my search.

Thanks
Pankaj
0
Ravindra76Commented:
Thanks.

 But i expected minimum B grade.

Ok.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.