I wish to create an application using swing to update data to the database. I will need three buttons add, modify and delete.
i have so far created JDBC connection with Ms acess. i have also created a textfield where i will enter data like this...

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
/*<applet code="textfield" width=300 height=200></applet>*/
public class textfield extends JApplet implements ActionListener
{
  JTextField jtf;
  public void init()
 {
   Container cp=getContentPane();
   cp.setLayout(new FlowLayout());
   jtf=new JTextField(15);
   cp.add(jtf);
 }
 public void actionPerformed(ActionEvent ae)
 {
  repaint();
 }
public void paint(Graphics g)
{
 g.drawString(jtf.getText(),100,80);
}
}

i wish to connect swing(applet) to database.Also i am not able to view text through the paint function on the applet.

my jdbc

import java.sql.*;
    public class Test4
    {
    public static void main(String[] args)
    {
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    
    String dataSourceName = "mdbTest1";
    String dbURL = "jdbc:odbc:" + dataSourceName;
    Connection con = DriverManager.getConnection(dbURL, "",""); 

    Statement s = con.createStatement();
    s.execute("create table TEST1223 ( id integer, name VARCHAR(32) )");
    s.execute("insert into Test1223"+"(id,name)"+"values('1001','nikhil')");
    s.execute("insert into Test1223"+"(id,name)"+"values('1002','ketan')"); 	
    s.close(); // close the Statement to let the database know we're done with it
    con.close(); // close the Connection to let the database know we're done with it
    }
    catch (Exception err) {
    System.out.println("ERROR: " + err);
    }
    }
    }

i would love if someone helps with this code(modify it) also something about "modify"button(its nature)

MS Access is file based (i.e. no remote connections, local file access needed) and Applets do not have access to the local file system. A complete redesign is in order.

I need more details. I don't understand what you are actualy doing. The best method would be to make a JTable in which you can see your database table records. Then you can go further. I mean how can you modify something if you can't see what row u actualy modify? (I'm guessing)

I think that you can write a server/client solution to get it to work. The client connects to the server which returns the content of the database. I did something like that when I needed my applet to read from a database, but I don't remember all the details.

I need more details. I don't understand what you are actualy doing. The best method would be to make a JTable in which you can see your database table records. Then you can go further. I mean how can you modify something if you can't see what row u actualy modify? (I'm guessing)

Under normal circumstances, how is he to access an MS Access DB from an Applet? It is the pinnacle of arrogance to suggest that the clients should modify their security settings for your app.

I think that you can write a server/client solution to get it to work. The client connects to the server which returns the content of the database. I did something like that when I needed my applet to read from a database, but I don't remember all the details.

An applet has no problems connecting to a DB, as long as the DB exists on the same server as the machine that served the page, and the DB is a client/server DB and not MS Access.

Of course you can build your own client/server protocol and connection to enable connection to MS Access, but why? Why pay the hefty license and software costs only to have to build your own (possibly buggy) access routines in order to be able to even use it when there are a plethora of free client/server DBs out there, and most of them are better than MS Access in the first place.

Edited 7 Years Ago by masijade: n/a

MS Access is file based (i.e. no remote connections, local file access needed) and Applets do not have access to the local file system. A complete redesign is in order.

Sorry, of course a complete redesign is not in order, but you do need to change DBs.

The question i have is: Create a java application which will add, modify,delete records from employee database.The database has 3 fields emp_id, empname and department location.All information accepted from GUI and stored in the database(hint:use jdbc)

so in the first part of my code i was trying to create a textfield for data entry. When i enter text in the textfield and click the add button the information should get updated in the database.We will be using MS access as the database.

In the next code i have just demonstrated what code i will be using as a response to the GUI event.

It need not be an applet but any GUI java application.dialog box, Jpane etc.(calling functions using main())

Then normal swing standalone app.

A preparedstatement, its setString method, and the textfields getText method.

That should get you started.

Can u please get me clear with how i should configure events like the button clicked and also how do i write two classes ..i mean one for swing and other for jdbc.May be a bad question for my level ...what does actionPerformed do and also addActionListener in general and in this case

i did not get that..was that a link? just tell me how i can include both swings and jdbc classes in one program..sorry i have lost touch a bit

This question has already been answered. Start a new discussion instead.