Hi
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");
f.setVisible(true);
f.setSize(300,300);
f.getContentPane().add(p);
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);
b.addActionListener(this);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
Object o=ae.getSource();
/*if (o==b)
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc
dbc:testdatasource", "", "");
preparedStatement st=con.prepareStatement("insert into table (t_roll,t_name,t_age) values (?,?,?)");
st.setString(1,t.getText());
st.setString(2,t1.getText());
st.setString(3,t2.getText());
st.setstring(4,(String)cb.getSelectedItem());
st.executeUpdate();
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 applet...as this code is with swing
application..
4 The information about the policy can be found here
http://java.sun.com/developer/onlineTraining/Security/Fundamentals/Security.html#secPolicyTool Enjoy