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)