Home > Back-end >  No error, but this series table display, but loaded from the database data don't show that big
No error, but this series table display, but loaded from the database data don't show that big

Time:12-02


Import the Java. The awt. BorderLayout.
Import the Java. The awt. EventQueue;
import java.sql.Connection;
Import the Java. SQL. DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

The import javax.mail. Swing. JFrame;
The import javax.mail. Swing. JPanel;
The import javax.mail. Swing. Border. EmptyBorder;
The import javax.mail. Swing. Table. DefaultTableModel;
The import javax.mail. Swing. JLabel;
The import javax.mail. Swing. JOptionPane;
The import javax.mail. Swing. GroupLayout;
The import javax.mail. Swing. GroupLayout. Alignment;
The import javax.mail. Swing. The JScrollPane;
The import javax.mail. Swing. This series;
import javax.swing.JTextField;
The import javax.swing.LayoutStyle.Com ponentPlacement;
The import javax.mail. Swing. JButton;

Public class dbtest extends JFrame {

Private JPanel contentPane.
Private data jtable1;

/* *
* to Launch the application.
*/
Public static void fillTable (data table) {
Try {//column
String [] column={" id ", "class", "grade"};
DefaultTableModel DefaultTableModel=new DefaultTableModel (column, 5);
The String url="JDBC: mysql://localhost: 3306/userdb? ServerTimezone=UTC ";
Class.forName("com.mysql.cj.jdbc.Driver");
The Connection conn=DriverManager. GetConnection (url, "root", "090627");
Statement stmt=conn.createStatement();
String SQL="select * from sc";
The ResultSet rs=STMT. ExecuteQuery (SQL);
While (rs), next ()) {
String userid=rs. Get String (" userid ");
String cno=rs. Get String (cno "");
String grade=rs. Get String (" grade ");
Object [] STR={userid, cno, grade};
DefaultTableModel. AddRow (STR);
}
rs.close(); stmt.close(); conn.close();
Table. SetModel (defaultTableModel);
}
The catch (Exception e) {JOptionPane. ShowMessageDialog (null, "loading is not successful!" ); }

}
Public static void main (String [] args) {
EventQueue. InvokeLater (new Runnable () {
Public void the run () {
Try {
Dbtest frame=new dbtest ();
Frame. SetTitle (" data ");
Dbtest. FillTable (frame. Jtable1);
frame.setVisible(true);
} the catch (Exception e) {
e.printStackTrace();
}
}
});
}

/* *
* Create the frame.
*/
Public dbtest () {
SetDefaultCloseOperation (JFrame. EXIT_ON_CLOSE);
SetBounds (100, 100, 450, 300);
ContentPane=new JPanel ();
ContentPane. SetBorder (new EmptyBorder (5, 5, 5, 5));
SetContentPane (contentPane);

The JScrollPane scrollPane=new JScrollPane (jtable1);
GroupLayout gl_contentPane=new GroupLayout (contentPane);
Gl_contentPane. SetHorizontalGroup (
Gl_contentPane. CreateParallelGroup (Alignment. The TRAILING)
AddGroup (gl_contentPane. CreateSequentialGroup ()
. AddGap (38)
AddComponent (scrollPane, GroupLayout. PREFERRED_SIZE, 310, GroupLayout PREFERRED_SIZE)
. AddContainerGap (78, Short. MAX_VALUE))
);
Gl_contentPane. SetVerticalGroup (
Gl_contentPane. CreateParallelGroup (Alignment. LEADING)
AddGroup (gl_contentPane. CreateSequentialGroup ()
AddContainerGap ()
AddComponent (scrollPane, GroupLayout. PREFERRED_SIZE, 111, GroupLayout PREFERRED_SIZE)
. AddContainerGap (132, Short. MAX_VALUE))
);

Jtable1=new series ();
ScrollPane. SetViewportView (jtable1);
ContentPane. SetLayout (gl_contentPane);
}
}

CodePudding user response:

The
refer to the original poster CHANGES125 response:

Import the Java. The awt. BorderLayout.
Import the Java. The awt. EventQueue;
import java.sql.Connection;
Import the Java. SQL. DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

The import javax.mail. Swing. JFrame;
The import javax.mail. Swing. JPanel;
The import javax.mail. Swing. Border. EmptyBorder;
The import javax.mail. Swing. Table. DefaultTableModel;
The import javax.mail. Swing. JLabel;
The import javax.mail. Swing. JOptionPane;
The import javax.mail. Swing. GroupLayout;
The import javax.mail. Swing. GroupLayout. Alignment;
The import javax.mail. Swing. The JScrollPane;
The import javax.mail. Swing. This series;
import javax.swing.JTextField;
The import javax.swing.LayoutStyle.Com ponentPlacement;
The import javax.mail. Swing. JButton;

Public class dbtest extends JFrame {

Private JPanel contentPane.
Private data jtable1;

/* *
* to Launch the application.
*/
Public static void fillTable (data table) {
Try {//column
String [] column={" id ", "class", "grade"};
DefaultTableModel DefaultTableModel=new DefaultTableModel (column, 5);
The String url="JDBC: mysql://localhost: 3306/userdb? ServerTimezone=UTC ";
Class.forName("com.mysql.cj.jdbc.Driver");
The Connection conn=DriverManager. GetConnection (url, "root", "090627");
Statement stmt=conn.createStatement();
String SQL="select * from sc";
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull