问下  在JTextField  写东西  然后点一个JButton按钮
 然后在JTable上面显示出来  并写入到SQL数据库驱动程序不用写了 
谁能帮我写个简单的 就一个JTextField   一个JButton  就行了 
谁能帮写下啊!

解决方案 »

  1.   

    import java.sql.*;
    import java.awt.*;
    import java.awt.event.*;public class OraUpdate extends Frame{
    private Panel p = null;
    private TextField ta = null;
    private TextField tb = null;
    private Button btnOK = null;
    Connection conn = null;
    Statement sta = null;
    ResultSet rs = null;
    int res = 0;


    public OraUpdate(){
    p = new Panel();
    ta = new TextField(4);
    tb = new TextField(10);
    btnOK = new Button(" OK ");

    add(p);
    p.add(ta);
    p.add(tb);
    p.add(btnOK);

    addWindowListener(new WindowEventHandler());
    btnOK.addActionListener(new ActionEventHandler());

    setTitle("Ora Control");
    setSize(300,100);
    show();
    }

    class WindowEventHandler extends WindowAdapter{
    public void windowClosing(WindowEvent e){
    System.out.println("系统退出:exit()");
    System.exit(0);
    }
    }

    class ActionEventHandler implements ActionListener{  
    public void actionPerformed(ActionEvent e){
    System.out.println ("**********");
    int i = Integer.parseInt(ta.getText());
    String str = tb.getText();
    UpdateSql(i, str);
    }
    }

    public void UpdateSql(int i, String str){
    try{
    String sqlUp ="";
    if(SelectSql(i)){
    System.out.println ("Update");
    sqlUp = "update aa set name='"+str+"' where num="+i;
    }else{
    System.out.println ("Insert");
    sqlUp = "insert into aa values("+i+",'"+str+"')";
    }

    Class.forName("oracle.jdbc.driver.OracleDriver");
    conn = DriverManager.getConnection("jdbc:oracle:thin:@172.17.93.117:1521:ora","scott","tiger");
    sta = conn.createStatement();
    res = sta.executeUpdate(sqlUp);
    System.out.println ("===========: "+res);

    conn.commit();
    sta.close();
    conn.close();
    }catch(Exception e){
    System.out.println ("++"+e);
    }
    }

    public boolean SelectSql(int i){
    try{
    String sqlSel = "select "+i+" from aa";
    Class.forName("oracle.jdbc.driver.OracleDriver");
    conn = DriverManager.getConnection("jdbc:oracle:thin:@172.17.93.117:1521:ora","scott","tiger");
    sta = conn.createStatement();
    rs = sta.executeQuery(sqlSel);
    while(rs.next()){
    rs.close();
    sta.close();
    conn.close();
    System.out.println ("@@@@@@@@@true");
    return true;
    }
    rs.close();
    sta.close();
    conn.close();

    }catch(Exception e){
    System.out.println ("++"+e);
    }
    System.out.println ("@@@@@@@@@False");
    return false;
    }
    /**
     * Method main
     *
     *
     * @param args
     *
     */
    public static void main(String[] args) {
    new OraUpdate();
    }
    }
    基本上是这样的,我用的是ACCESS数据库,但是有的地方还不很完善,仅供参考~~
      

  2.   

    JTextField text = new JTextField;
    JButton button = new JButton("write in");
    button.addMouseListener(new MouseListener(){
        public void MousePressed(){
            String content = text.getText();
            if(content != null){
                Statement stmt = conn.createStatement();
                stmt.execute("insert into sqltable values( " + content = ")"); 
            } 
        }
    })