• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

JDBC - Applet - Swing

 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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.
 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,
blah,
blah,
blah

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

BSc (Comp Eng), SCJP 1.4 , SCWCD (in progress)
 
Ranch Hand
Posts: 824
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Niyas Ahmed Sheikh
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!
 
Farmers know to never drive a tractor near a honey locust tree. But a tiny ad is okay:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic