-1
   DBUtil util = new DBUtil();
        try {
            JOptionPane.showMessageDialog(null, "Connection Opened!");
            Connection con = util.getConnection();
            PreparedStatement stmt = con.prepareStatement("SELECT (SUM(box_no),SUM(weight),SUM(TP),SUM(TV)) FROM dbo.mut_det WHERE rm_id=?");
            stmt.setInt(1, Integer.parseInt(rm));// but how to get values from textfield dont know.
            //*and how to put these called values SUM(box_no),SUM(weight),SUM(TP),SUM(TV) in textfields dnt know.*//
            //my textfields are txtboxno, txtweight, txttp, txttv
            stmt.execute();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage());
            Logger.getLogger(Demo.class.getName()).log(Level.SEVERE, null, ex);
        }

you see not able to get and put values back into textfields...

Sumeet Gavhale
  • 800
  • 4
  • 13
  • 39
  • please help guyz...!! :-( – Sumeet Gavhale Dec 27 '12 at 23:11
  • 2
    What specifically are you having trouble with? Writing the SQL? A portion of the interface? I see the insert code; what have you tried for the search function? – Aaron Kurtzhals Dec 27 '12 at 23:14
  • i used...// * CallableStatement stmt = con.callableStatement("SELECT (rm_id,SUM(box_no),SUM(weight),SUM(TP),SUM(TV) FROM dbo.mut_det WHERE(rm_id=?); * // BUT IT DID NOT WORKED – Sumeet Gavhale Dec 27 '12 at 23:20
  • I got what you want to do, but I did not get where you are getting problem? and one more thing dont put your code in comment box. It make unreadable here. – Smit Dec 27 '12 at 23:21
  • oh sorry for that.. :-( well i want to take the value of rm_id from the text field: tf_rm_id and also i want to display the called records to my another textfields but not any idea of doing so therefore i request the help.. – Sumeet Gavhale Dec 27 '12 at 23:25
  • but if i want to get the rm_id which is ? from any textfield how would i take it?? – Sumeet Gavhale Dec 27 '12 at 23:44
  • stmt.execute(); should be executeQuery which will return resultSet. oterwise you would have to call additional methods to determine if the execute returns a resultset and then extract methods from resultset – Usman Saleem Dec 27 '12 at 23:56

1 Answers1

1

Here is dirty sample code that might help to resolve your issue.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class TextDemo extends JFrame implements ActionListener {
    JTextField textData;
    JButton button = new JButton("Press Me");

    public TextDemo() {
        JPanel myPanel = new JPanel();
        add(myPanel);
        myPanel.setLayout(new GridLayout(3, 2));
        myPanel.add(button);
        button.addActionListener(this);
        textData = new JTextField();
        myPanel.add(textData);
    }


    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == button) {
            String data = textData.getText(); // perform your DB operation
            textData.setText(data + " This is new text"); // Set your DB values.
        }
    }

    public static void main(String args[]) {
        TextDemo g = new TextDemo();
        g.setLocation(10, 10);
        g.setSize(300, 300);
        g.setVisible(true);
    }
}
Smit
  • 4,685
  • 1
  • 24
  • 28