Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从数据库中检索值并显示在文本字段中_Java_Database_Jdbc - Fatal编程技术网

Java 从数据库中检索值并显示在文本字段中

Java 从数据库中检索值并显示在文本字段中,java,database,jdbc,Java,Database,Jdbc,您看到无法获取值并将其放回文本字段…以下是脏的示例代码,可能有助于解决您的问题 DBUtil util = new DBUtil(); try { JOptionPane.showMessageDialog(null, "Connection Opened!"); Connection con = util.getConnection(); PreparedStatement stmt = con.pr

您看到无法获取值并将其放回文本字段…

以下是脏的示例代码,可能有助于解决您的问题

   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);
        }

请帮助guyz…!!:-(您在编写SQL时遇到了什么具体问题?接口的一部分?我看到了插入代码;您尝试了什么搜索功能?我使用了…/*CallableStatement stmt=con.CallableStatement(“从dbo.mut det WHERE(rm_id=?)中选择(rm_id,SUM(box_no),SUM(weight),SUM(TP),SUM(TV));*//但它不起作用我得到了你想要做的,但我没有得到你遇到的问题?还有一件事不要把你的代码放在评论框中。这会使这里无法阅读。哦,很抱歉-(好吧,我想从文本字段中获取rm_id的值:tf_rm_id,并且我想将调用的记录显示到我的另一个文本字段中,但我不想这样做,因此我请求帮助.)。。
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);
    }
}