File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes JDBC - Applet - Swing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "JDBC - Applet - Swing" Watch "JDBC - Applet - Swing" New topic

JDBC - Applet - Swing

Niyas Ahmed Sheikh
Ranch Hand

Joined: Jun 15, 2005
Posts: 129

I want to connect applet with Ms-Access. For example, I want to add, update, insert and delete the records in the MS-Access thru Applet or Swing.
I had searched this topic in this forum, but it is not too clear to clear my doubts.
To write a program in Applet to connect with JDBC(MS-Access), what are all the steps needs to be done.
What is Policytool? Any sample coding connecting applet with MS-Access will be helpful.
s mahen perera
Ranch Hand

Joined: Mar 08, 2005
Posts: 101
Hi niyaz,

basically what u want to do is connect to a DB from the applet right?

an Applet will restrict certain operations to be done on the local file system, since the applet will be executed in a sand box. However, there is no restriction for an applet to connect to a DB which is located in the local machine AFAIK. (so no need to worry abt any security policies. ) The steps are the same as for the case ur writing a Java Swing client to connect to a DB using JDBC.

First load the correct driver,
Create the connection object,

Hope i answered u. Get back if ur not clear. Good Luck

BSc (Comp Eng), SCJP 1.4 , SCWCD (in progress)
Sunil Kumar Gupta
Ranch Hand

Joined: Aug 26, 2005
Posts: 824

check this code

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;

class test implements ActionListener

JFrame f;
JPanel p;

JLabel l,l1,l2,l3;

JTextField t,t1,t2;
JComboBox cb;
JButton b,b1;

public static void main(String s[])
new test();

public test()
p=new JPanel();
f=new JFrame("Test Window");


l=new JLabel("Roll No.:- ");
l1=new JLabel("Name :- ");
l2=new JLabel("Age :- ");
l3=new JLabel("Sex :-");

t=new JTextField(5);
t1=new JTextField(10);
t2=new JTextField(15);

String s[]={"Male", "Female"};
cb=new JComboBox(s);

b=new JButton("Insert");
b1=new JButton("Delete");

p.add(l); p.add(t);
p.add(l1); p.add(t1);
p.add(l2); p.add(t2);
p.add(l3); p.add(cb);

p.add(b); p.add(b1);


public void actionPerformed(ActionEvent ae)
Object o=ae.getSource();

/*if (o==b)

Connection con=DriverManager.getConnection("jdbc dbc:testdatasource", "", "");
preparedStatement st=con.prepareStatement("insert into table (t_roll,t_name,t_age) values (?,?,?)");


JOptionPane.showMessageDialog(p,"record added", "Information",3);

catch(Exception e)
System.out.println("Error !!! " + e);

Here in the code.......the lines noticable are---

1 Class.forName("") The string which is passed in this
is the url of jdbc-odbc bridge driver
2 getConnection(": :testdatasource") this is the dsn u would create
for ur application, which will point ur ms access database....

3 U can create the same code for an this code is with swing

4 The information about the policy can be found here


Lack of will power has caused more failure than lack of intelligence or ability.
My Blog | Red5 Resources | Technology Update | Daily Technology Tips
Niyas Ahmed Sheikh
Ranch Hand

Joined: Jun 15, 2005
Posts: 129
Hi Guys,

Thanks to both mahen and sunil.

The coding given by you will be very useful. I will try this coding and If I have anydoubt in it, I will come back!!

Once again thank you for your prompt reply!!
I agree. Here's the link:
subject: JDBC - Applet - Swing
It's not a secret anymore!