Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/308.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 Swing、Jtable、JDBC_Java_Swing_Jdbc_Jtable_Resultset - Fatal编程技术网

Java Swing、Jtable、JDBC

Java Swing、Jtable、JDBC,java,swing,jdbc,jtable,resultset,Java,Swing,Jdbc,Jtable,Resultset,} 有谁能告诉我如何将数据插入数据库的JTable表中吗。这是我不完整的代码。我已经创建了一个表,但我不知道如何将数据以网格格式插入数据库,这样就可以编辑表中的数据并在数据库中更新。感谢您的时间和考虑,将JTable列名另存为字符串数组,将数据另存为任何类型的二维数组。您可以通过从数据库检索数据来填充数据数组 以下链接有一个示例(无数据库) 下面是Oracle指南,它非常好 我知道如何从数据库中检索数据,但我不知道如何使用TableModel将数据插入表中。你是否在谷歌上搜索了你的问题?为什么

}
有谁能告诉我如何将数据插入数据库的JTable表中吗。这是我不完整的代码。我已经创建了一个表,但我不知道如何将数据以网格格式插入数据库,这样就可以编辑表中的数据并在数据库中更新。感谢您的时间和考虑,将JTable列名另存为
字符串数组
,将数据另存为
任何类型的二维数组
。您可以通过从数据库检索数据来填充数据数组

以下链接有一个示例(无数据库)

下面是Oracle指南,它非常好


我知道如何从数据库中检索数据,但我不知道如何使用TableModel将数据插入表中。你是否在谷歌上搜索了你的问题?为什么本页后缘的链接都没有帮助你至少一个初学者?您确实读过它们(至少在标题中包含jdbc/数据库的部分),是吗?无关:a)不要手动调整组件大小/定位,这是LayoutManager的专有任务b)必须在EDT上访问swing组件(无论如何,使用当前时间更新标签的部分与您的问题有什么关系?)您认为如果我这样做,是否可以编辑、更新或删除表或任何特定值,进而更新数据库……链接包含编辑/插入值到JTable的方式。其余部分取决于您的应用程序逻辑a)roseindia引用它完全不相关(而且非常琐碎,同时又非常复杂,这会造成伤害,正如我经常看到的那样)b)教程链接也不相关,尽管总是一个很好的开端
  package com.officelog.manager;

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


  public class AdminControl implements Runnable{
public static void main(String[] args) {
    new AdminControl();
}

Thread t = null ;
int hour ,minute,second ;
int year,month,day ;
int Month ;


private static JFrame frame = new JFrame("Admin_Control");
static JPanel panel = new JPanel();
JLabel label,name,date,time;
JTable table ;
JScrollPane scrollpane ;
public AdminControl() {
    frame.setBounds(100, 100, 700, 600);
    frame.setResizable(false);
    frame.add(panel);

    panelSetUp();

    frame.setVisible(true);

}
private void panelSetUp() {
    panel.setLayout(null);
    panel.setBackground(Color.lightGray);
    panel.setBorder(BorderFactory.createBevelBorder(1,Color.white,   Color.white));



    time = new JLabel();
    panel.add(time);
    time.setBounds(20, 25, 70, 25);

    date = new JLabel();
    panel.add(date);
    date.setBounds(20, 75, 70, 25);

    t = new Thread(this);
    t.start();

    name = new JLabel("Name:");
    panel.add(name);
    name.setBounds(20,50,50,25);

    label = new JLabel("SuperUser");
    panel.add(label);
    label.setBounds(60, 50, 70, 25);
    label.setForeground(Color.blue);


    tableSetUp();
    JMenuBar menuBar = new JMenuBar();
    frame.add(menuBar,BorderLayout.NORTH);
    menuBar.setBorder(BorderFactory.createBevelBorder(1, Color.gray, Color.gray));

    JMenu file = new JMenu("File");
    menuBar.add(file);

    JMenu source = new JMenu("Source");
    menuBar.add(source);
}
public void run(){
    try{
        while(true){
            Calendar now = Calendar.getInstance();
            hour = now.get(Calendar.HOUR_OF_DAY);
            minute = now.get(Calendar.MINUTE);
            second = now.get(Calendar.SECOND);

            year = now.get(Calendar.YEAR); 

            Month = now.get(Calendar.MONTH);
            month = Month + 1;

            day = now.get(Calendar.DATE);
            displayDateTime();
            time.repaint();
            date.repaint();
            t.sleep(1000);
        }
        }catch(Exception e){
        e.printStackTrace();
    }
}

public void displayDateTime(){
    time.setText(hour+":"+minute+":"+second);
    date.setText(day+"/"+month+"/"+ year);
}

private void tableSetUp(){
    int row ;

    Object [][] data ={
            {new Integer(5),"Deepak","Deepak"
                ,"2013-21-03"
            }
    };
    String columnNames []={"EmployeeID" , "EmployeeName",
            "EmployeePassword","CreatedOn"};
    table = new JTable(data , columnNames);
    scrollpane = new JScrollPane(table);
    panel.add(scrollpane);
    scrollpane.setBounds(50, 200, 600, 100);
    table.setBounds(50, 100, 600, 100);
    table.setForeground(Color.BLUE);
    table.setGridColor(Color.pink);

}