当前位置: 代码迷 >> J2SE >> 表格 java输出数据库方法【大家赶紧来帮帮小弟我啊 着急死了】拜谢
  详细解决方案

表格 java输出数据库方法【大家赶紧来帮帮小弟我啊 着急死了】拜谢

热度:603   发布时间:2016-04-24 02:29:04.0
求一个 表格 java输出数据库方法【大家赶紧来帮帮我啊 着急死了】拜谢
因为用netbeans,那个设计UI的,自己先画了一个表格,想让表格输出数据库一个表的内容,求大家帮我写个. 链接oracle数据库

http://hi.csdn.net/attachment/201107/20/5429004_13111524932285.png


也可以帮我先写个 简单的例如 数据库的student表,内容有 name ,id,age 我在类推学习一下


Java code
public class student extends javax.swing.JFrame {    /** Creates new form student */    public student() {        initComponents();    }    /** This method is called from within the constructor to     * initialize the form.     * WARNING: Do NOT modify this code. The content of this method is     * always regenerated by the Form Editor.     */    @SuppressWarnings("unchecked")    // <editor-fold defaultstate="collapsed" desc="Generated Code">    private void initComponents() {        jPanel1 = new javax.swing.JPanel();        jScrollPane1 = new javax.swing.JScrollPane();        jTable1 = new javax.swing.JTable();        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);        jTable1.setModel(new javax.swing.table.DefaultTableModel(            new Object [][] {                {null, null, null},                {null, null, null}            },            new String [] {                "姓名", "学号", "年龄"            }        ) {            boolean[] canEdit = new boolean [] {                false, false, true            };            public boolean isCellEditable(int rowIndex, int columnIndex) {                return canEdit [columnIndex];            }        });        jTable1.getTableHeader().setReorderingAllowed(false);        jScrollPane1.setViewportView(jTable1);        jTable1.getColumnModel().getColumn(0).setResizable(false);        jTable1.getColumnModel().getColumn(1).setResizable(false);        jTable1.getColumnModel().getColumn(2).setResizable(false);        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);        jPanel1.setLayout(jPanel1Layout);        jPanel1Layout.setHorizontalGroup(            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(jPanel1Layout.createSequentialGroup()                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 375, javax.swing.GroupLayout.PREFERRED_SIZE)                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))        );        jPanel1Layout.setVerticalGroup(            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(jPanel1Layout.createSequentialGroup()                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE)                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))        );        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());        getContentPane().setLayout(layout);        layout.setHorizontalGroup(            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(layout.createSequentialGroup()                .addContainerGap()                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))        );        layout.setVerticalGroup(            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(layout.createSequentialGroup()                .addContainerGap()                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))        );        pack();    }// </editor-fold>    /**     * @param args the command line arguments     */    public static void main(String args[]) {        java.awt.EventQueue.invokeLater(new Runnable() {            public void run() {                new student().setVisible(true);            }        });    }    // Variables declaration - do not modify    private javax.swing.JPanel jPanel1;    private javax.swing.JScrollPane jScrollPane1;    private javax.swing.JTable jTable1;    // End of variables declaration}
  相关解决方案