Meaningless Drivel is fun!*
The moose likes JDBC and the fly likes JDBC - Applet - Swing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC - Applet - Swing" Watch "JDBC - Applet - Swing" New topic
Author

JDBC - Applet - Swing

Niyas Ahmed Sheikh
Ranch Hand

Joined: Jun 15, 2005
Posts: 129
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.
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,
blah,
blah,
blah

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
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



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: http://aspose.com/file-tools
 
subject: JDBC - Applet - Swing