PDA

View Full Version : db connect through applet


gtriant
11-25-2007, 02:14 PM
I use the following code inside my applet to connect to the db.

try {
Context ctx = new InitialContext();
if (ctx == null)
throw new Exception("Error - No Context!!!");

Context envContext = (Context)ctx.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/myDB");

con = ds.getConnection();
} catch (Exception e ){
e.printStackTrace();
}

But I am not getting the results that i need inserted, after the applet has finished running. I know almost nothing about applets, so any help is much appreciated!!!
Is it possible for me to connect to the db through an applet loaded on a web page?? Both wep application and db are on the same host. What's wrong with the above code???

PS. I hope this is the right place for the post....

gtriant
11-26-2007, 10:00 AM
Has anyone connected to a db through an applet running on a server?
I would appreciate if someone could tell me if it can be done.
I would appreciate even more some sample code!!!

BTW, I declare the db host inside my context.xml file of my web app (as I would do for every db access of a web-app). Is that viewable from within the applet, or could that be my problem???