|

楼主 |
发表于 2017-6-21 15:52:10
|
显示全部楼层
新鲜的错误代码为大神们献上,列的名字显示不出来?
- import java.sql.Connection;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import javax.swing.JFrame;
- import javax.swing.JTable;
- import com.cdd.jdbc.GetConn;
- public class Main {
- public static void main(String[] args) {
- frame A = new frame();
- }
- }
- class frame extends JFrame {
- public frame() {
- int j = 0, i = 0;
- String sql2 = "select *from student_information order by userID";
- String sql1 = "select *from student_information";
- String B[] = { "学号", "姓名", "性别", "生日", "民族", "年纪", "专业" };
- setSize(400, 400);
- setResizable(true);
- setVisible(true);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- GetConn getconn = new GetConn();
- Connection conn = getconn.getConnection();
- try {
- Statement statement1 = conn.createStatement();
- ResultSet resultSet1 = statement1.executeQuery(sql1);
- while (resultSet1.next()) {
- i++;
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- Object A[][] = new Object[i][7];
- Statement statement2;
- try {
- statement2 = conn.createStatement();
- ResultSet resultSet2 = statement2.executeQuery(sql2);
- while (resultSet2.next()) {
- A[j][0] = resultSet2.getString("userID");
- A[j][1] = resultSet2.getString("name");
- A[j][2] = resultSet2.getString("sex");
- A[j][3] = resultSet2.getInt("birdathy");
- A[j][4] = resultSet2.getString("nation");
- A[j][5] = resultSet2.getInt("class");
- A[j][6] = resultSet2.getString("zhaunye");
- j++;
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- JTable jTable1 = new JTable(A, B);
- add(jTable1);
- }
- }
复制代码
|
-
|